New
#270
That's what your link says:
"If you like, you could use the same command in a .bat file. You would just need to right click on the .bat file and click on "Run as administrator"."
Hi Fabfisc,
The below batch script will enable the Administrator account if the account is disabled, and vice versa.
And a VBScript translate of the above,Code:@net session >NUL 2>&1||powershell Start-Process '%0' -Verb RunAs>NUL&&exit /b|| exit /b @net user Administrator|find "active"|find "Yes">NUL&&( net user Administrator /active:no&&echo The Administrator account is now Disabled. )||( net user Administrator /active:yes&&echo The Administrator account is now Enabled. ) @timeout 2 >NUL & rem tsdiscon
Code:Set objShell = CreateObject("WScript.Shell") If Not objShell.Run("Net Session",0,True) = 0 Then CreateObject("Shell.Application").ShellExecute "WScript.exe", WScript.ScriptFullName,"","RunAs",1 WScript.Quit End If If objShell.Run("cmd /c ""Net User Administrator|Find ""active""|Find ""Yes""""", 0, True) = 0 Then objShell.Run "Net User Administrator /Active:No", 0, True objShell.Popup "The Administrator account is now Disabled.", 1.5, "Success", 64 Else objShell.Run "Net User Administrator /Active:Yes", 0, True objShell.Popup "The Administrator account is now Enabled.", 1.5, "Success", 64 End If rem WScript.Sleep 2000 : objShell.Run "tsdiscon", 0, True
It seems that when i run both scripts, i receive the same result:
"The Administrator account is now Enabled."
All that even if i see (by typing "net use administrator") the referred value of variable "Enable account" set to "Yes"
It seems that the second time i run the script it doesn't see the value "Yes"...
Half solved!
Here is the correct script for the vbs part:
Trying to find the right way to do the same via .cmd (for now, it always returns "The Administrator account is now Enabled."Dim WshShell : set WshShell = Wscript.CreateObject("WScript.Shell")
If WshShell.Run("cmd /c ""Net User Administrator|Find ""attivo""|Find ""Sì""""", 0, True) = 0 Then
WshShell.Run "Net User Administrator /active:No", 0, True
WshShell.Popup "The Administrator account is now Disabled.", 1.5, "Success", 64
Else
WshShell.Run "Net User Administrator /active:Yes", 0, True
WshShell.Popup "The Administrator account is now Enabled.", 1.5, "Success", 64
End If
Last edited by fabfisc; 03 Apr 2015 at 02:30. Reason: rectification
Ah. Silly me. I didn't take your country flag into account, Fabfisc.
So here is what the Italian verson for the batch (.bat|.cmd) version of the enable/disable Administrator script would look like.
Code:@net session >NUL 2>&1||powershell Start-Process '%0' -Verb RunAs>NUL&&exit /b|| exit /b @net user Administrator|find "attivo"|find "Si">NUL&&( net user Administrator /active:no&&echo The Administrator account is now Disabled. )||( net user Administrator /active:yes&&echo The Administrator account is now Enabled. ) @timeout 2 >NUL & rem tsdiscon
By the way, in your VBScript, Fabfisc, you seem to have assigned to a variable retcode but you never use it. Please do something about it, it's making me cringe .
Last edited by Pyprohly; 02 Apr 2015 at 20:05.
Yep, i though i removed that line, it was only for test.
I edited and correct it.
Many thanks
Option 1 work Good. No Error
NOTE: This option can be used in all editions of Windows 7.
I tried this on my wife's laptop running Windows 7 Home Premium and it did not work. I don't see "Accessories" in her "all programs" list, but did search for "cmd" and it came up with cmd.exe. I right clicked it and chose run as administrator and the net use command produced an error message instead. Her account is an admin account, but I know she needs an elevated admin account. This just didn't work for her. Any ideas?
TIA,
S
Hello S,
Please go ahead and post a screenshot showing the command prompt after running the command to see what it says to see what may be wrong. :)