Skip to content

bug in install_shell64.cmd when "Server" service (lanmanserver) is stopped or disabled #6091

@badrelmers

Description

@badrelmers

Hi,
install_shell64.cmd and install_shell32.cmd use net session to check for admin right, this is bad and have several problems, in my case it make the check for admin right always fail and enter in an infinite loop like you see in this video:

contextmenubatchBug.mp4

The issue stems from the :CheckForAdminPermissions subroutine, which relies on the net session command to detect elevated (admin) privileges. This command fails and sets ERRORLEVEL to a non-zero value (typically 2) even when the script is already running as administrator if the "Server" service (lanmanserver) is stopped or disabled on the system. This is common on machines where file/printer sharing is turned off for security or performance reasons, as net session depends on that service being active.

As a result:

  • The check incorrectly assumes no admin rights.
  • The script attempts to restart itself elevated via the VBScript and ShellExecute call.
  • The new elevated instance runs into the same false negative, restarts again, and so on, creating the infinite loop of starting and closing.
  • When run without admin, it elevates once via UAC prompt, but then loops in the same way.

you can read more about this problem and other problems with net session here https://stackoverflow.com/questions/4051883/batch-script-how-to-check-for-admin-rights#comment29802533_11995662

To fix this, we have to update the :CheckForAdminPermissions subroutine to use a more reliable admin detection method that doesn't depend on the Server service. I always used fltmc to check for admin rights and it never gave this type of problems, and it was recommended in the above stackoverflow link as an alternative to net session too , and it works also for xp+ like net session.
so change this:

net session 1>NUL 2>&1

to this

fltmc 1>NUL 2>&1

i could not find where those batch files reside in this repo so i could not send a PR

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions