I recently contracted a virus on my Windows 7 machine (its all cleared up now) that deleted the environment variable %windir%. How would I go about launching a program in the powershell or otherwise in root now that I can't seem to run the "Run as administrator" command in the GUI (as well as many other programs). I guess what I am basically asking is if there is a sudo-like command I could run to fix this.
2 Answers
If the current console is not elevated and the operation you're trying to do requires elevated privileges then you can start powershell with the "Run as administrator" option
PS> Start-Process C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Verb runAs
Source: StackOverflow
-
I got the error "Start-Process : The system could not find the environment option tat was entered." I assume that occurred because of my non-existent %WINDIR% environment variable. Jul 10, 2013 at 0:52
-
Correct. In your case you have to specify the full path for "Powershell":
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
– nixdaJul 10, 2013 at 0:54 -
Alright I filled in the whole directory now but it still did not work. It did actually work though without the arguments (-Verb and runAs) you listed. Jul 10, 2013 at 1:02
-
Try c:\windows\system32\runas.exe /user:Administrator cmd.exe
Substitute your known local administrator account name for Administrator above. If you don't know the password, try looking into something called CHNTPW - a Linux utility/boot disk that can modify an offline Windows registry and reset the password.
-
Unfortunitely it said it could not find the find the file cmd.exe, even when I typed in the entire directory. This is truly strange to me. Jul 10, 2013 at 0:48
-
try
c:\windows\system32\runas.exe /user:Administrator c:\windows\system32\cmd.exe
Jul 10, 2013 at 0:54