Built-in Administrator Account - Enable or Disable

Page 28 of 29 FirstFirst ... 1826272829 LastLast

  1. Posts : 72,043
    64-bit Windows 11 Pro for Workstations
    Thread Starter
       #270
      My Computer


  2. Posts : 8
    Palermo
       #271

    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"."


      My Computer


  3. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #272

    fabfisc said:
    ...[I] need a script (better if vbs) to do that as i manage many new notebooks to initialize (for first time) and then enable the admin account.
    Hi Fabfisc,

    The below batch script will enable the Administrator account if the account is disabled, and vice versa.
    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
    And a VBScript translate of the above,
    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
      My Computer


  4. Posts : 8
    Palermo
       #273

    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"...
      My Computer


  5. Posts : 8
    Palermo
       #274

    Half solved!

    Here is the correct script for the vbs part:

    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
    Trying to find the right way to do the same via .cmd (for now, it always returns "The Administrator account is now Enabled."
    Last edited by fabfisc; 03 Apr 2015 at 02:30. Reason: rectification
      My Computer


  6. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #275

    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.
      My Computer


  7. Posts : 8
    Palermo
       #276

    Yep, i though i removed that line, it was only for test.

    I edited and correct it.

    Many thanks
      My Computer


  8. Posts : 1
    Windows 7 Ultimate x64
       #277

    Option 1 work Good. No Error
      My Computer


  9. Posts : 10
    Windows 7 Pro 64bit
       #278

    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
      My Computer


  10. Posts : 72,043
    64-bit Windows 11 Pro for Workstations
    Thread Starter
       #279

    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. :)
      My Computer


 
Page 28 of 29 FirstFirst ... 1826272829 LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 02:56.
Find Us