Setting administrator on login with a image

Discussion in 'Software' started by dwm8888, Jul 29, 2008.

  1. dwm8888

    dwm8888 Private E-2

    Hey,

    I am working for my college for the summer to complete a class and as part of that I am helping them create a new image to place on all student laptops. Right now we have the image working perfectly except that we can not get it to set the user to local administrator when they log in for the first time.

    We have tried using "NET LOCALGROUP Administrators /ADD %username%" and we get system error 5 due to lack of permissions since the user is not an administrator yet. We dont want to give them the power of the domain administrator but we do need them to be local admins. Any help in figuring this out would be greatly appreciated.
     
  2. dwm8888

    dwm8888 Private E-2

    I figured out the problem myself, but thank you to those who took the time to look over my issue. Below is the code used to solve the problem, it is in vbscript and is meant to be ran during startup so that the user may be set to administrator, or any other account type, with out having to log off.

    <code>
    'Sets option to explicit casting
    Option explicit

    'Creates two variables. oShell and usrnm.
    dim oShell
    dim usrnm

    'Sets the variable oShell equal to WScript.Shell
    set oShell= Wscript.CreateObject("WScript.Shell")

    'Sets the variable usrnm equal to the current username
    usrnm = oShell.ExpandEnvironmentStrings("%username%")

    'Opens command prompt and enters user ID and program information for the RunAs command
    oShell.Run "runas /user:AccountToRunUnder ""cmd.exe"""

    'Forces the program to wait for .1 seconds
    WScript.Sleep 100

    'Enters the password for the account to be run under
    oShell.Sendkeys "AccountPassword~"

    'Forces the program to wait .5 seconds
    WScript.Sleep 500

    'Enters the information to add current user to a local group of your choice
    oShell.Sendkeys "NET LOCALGROUP GroupOfChoice /ADD " & usrnm & "~"

    'Forces the program to wait .5 seconds
    WScript.Sleep 500

    'Closes the command prompt being run under another account
    oShell.Sendkeys "exit~"

    'Quites the script
    Wscript.Quit
    </code>

    I hope that someone else can find this useful, again thank you all and have a great day.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds