Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Reduce number of UAC elevation prompts #487

Open
8 of 29 tasks
rbuckton opened this issue Nov 11, 2019 · 7 comments
Open
8 of 29 tasks

Suggestion: Reduce number of UAC elevation prompts #487

rbuckton opened this issue Nov 11, 2019 · 7 comments

Comments

@rbuckton
Copy link
Contributor

rbuckton commented Nov 11, 2019

My Environment

  • Windows 7 or below (not truly supported due to EOL - see wiki for details)

  • Windows 8

  • Windows 8.1

  • Windows 10

  • Windows 10 IoT Core

  • Windows Server 2012

  • Windows Server 2012 R2

  • Windows Server 2016

  • My Windows installation is non-English.

I'm using NVM4W version:

  • 1.1.7
  • 1.1.6
  • 1.1.5
  • 1.1.4
  • 1.1.3
  • 1.1.2
  • 1.1.1
  • Older
  • OTHER (Please Specify)

I have already...

  • read the README to be aware of npm gotchas & antivirus issues.
  • reviewed the wiki to make sure my issue hasn't already been resolved.
  • verified I'm using an account with administrative privileges.
  • searched the issues (open and closed) to make sure this isn't a duplicate.
  • made sure this isn't a question about how to use NVM for Windows, since gitter is used for questions and comments.

My issue is related to (check only those which apply):

  • settings.txt
  • proxy support (Have you tried version 1.1.0+?)
  • 32 or 64 bit support (Have you tried version 1.1.3+?)
  • Character escaping (Have you tried version 1.1.6+?)
  • A standard shell environment (terminal/powershell)
  • A non-standard shell environment (Cmder, Hyper, Cygwin, git)

Expected Behavior

When changing the active NodeJS installation between versions, nvm should display a UAC elevation prompt at most once.

Actual Behavior

nvm displays a UAC elevation prompt twice:

nvm-windows/src/nvm.go

Lines 400 to 415 in 15c5743

sym, _ := os.Stat(env.symlink)
if sym != nil {
if !runElevated(fmt.Sprintf(`"%s" cmd /C rmdir "%s"`,
filepath.Join(env.root, "elevate.cmd"),
filepath.Clean(env.symlink))) {
return
}
}
// Create new symlink
if !runElevated(fmt.Sprintf(`"%s" cmd /C mklink /D "%s" "%s"`,
filepath.Join(env.root, "elevate.cmd"),
filepath.Clean(env.symlink),
filepath.Join(env.root, "v"+version))) {
return
}

Steps to reproduce the problem:

  1. With nvm disabled (i.e. no symlinks exist) and two different installed versions of NodeJS (X and Y):
    1. nvm use X for an installed version X. UAC prompt appears once.
    2. nvm use Y for an installed version Y. UAC prompt appears twice.
@coreybutler
Copy link
Owner

Once runElevated is executed once, it shouldn't prompt again. That said, I have seen this occur from time to time, never being able to identify a specific Windows build in which it occurs.

@rbuckton can you provide the specific Windows build you're running? Thanks in advance.

@rbuckton
Copy link
Contributor Author

I'm running Windows 10 1703, but I think this is more of a function of Group Policy and/or UAC settings:

image

@rbuckton
Copy link
Contributor Author

Another note: It is not necessary to elevate to create symlinks in Windows 10 following build 14972 if you have Developer Mode enabled: https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/

In addition to only requesting elevation once, I would suggest updating the script that creates the symlinks to first try to create the symlink without elevation, then fall back to elevation if that fails.

@rbuckton
Copy link
Contributor Author

You can test for whether Developer Mode is enabled by checking the value of HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock\AllowDevelopmentWithoutDevLicense (DWORD=1)

https://docs.microsoft.com/en-us/windows/uwp/get-started/enable-your-device-for-development

You can also get the version of windows using wmic os get Version /value

@rbuckton
Copy link
Contributor Author

(though its still necessary to elevate to write to \Program Files, so I'm not sure if the above will help)

@frostbytedata
Copy link

I have this same exact issue and it is extremely annoying having to agree to 2 consecutive prompts.

image

image

image

Any way to limit this? I don't seem to have this issue on my laptop. I will try to hop on and add the build info for that machine as soon as I can.

@inseopark
Copy link

inseopark commented Apr 7, 2020

I think if someone can adjust windows UAC prompt settings, then they can also adjust their privileges to create symbolic link. please see secuirty-policy-settings.

this vbscript changes works based assuming:

  • user can have SeCreateSymbolicLinkPrivilege
  • user makes %NVM_SYMLINK% symbolic link directory on Modifiable path
    (Normally, Program Files directory, user with SeCreateSymbolicLinkPrivilege can not make symbolic link.)

If your pc is controlled by domain controller, Domain Administrator would prefer to give symbolicLinkPrivilege rather than change UAC settings.

please adjust elevate.vbs like below

' add below code after Set ProcEnv = WShell.Environment("PROCESS")
Const WshRunning = 0
Const WshFinished = 1
Const WshFailed = 2

Dim objStdOut
Dim exec     : Set exec = WShell.Exec("whoami.exe /priv")
Set objStdOut = exec.StdOut
Dim shexoption : shexoption = "runas"
Dim strLine

While exec.Status = WshRunning
    WScript.Sleep 2
Wend


If exec.Status = WshFinished Then
	Do Until objStdOut.AtEndofStream
		strLine = objStdOut.ReadLine
		If InStr(strLine,"SeCreateSymbolicLinkPrivilege") Then
			shexoption = "open"
			Exit do
		End If
	loop
End If
Set exec = Nothing
Set objStdOut = Nothing

finally change shell.ShellExecute routine like below:
Shell.ShellExecute app, args, "", shexoption, 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants