Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having problems installing printers/software on a locked down system ?

Status
Not open for further replies.

Pyro777

MIS
Jul 14, 2006
47
US
Here are 3 seperate scripts I wrote that might just help you.

As you know, you cannot install an printer in a locked down XP system due to the ACL requiring you to be an Administrator to install the drivers/USB connection. This sequence of scripts will allow you to have your user login as themselves, run the 1st script (Tempaccess.vbs), which will use the lsrunas.exe commandline utility to add that logged in user to the local administrators group. After adding the user, it will then copy the BootonceTEK.vbs script to the startup folder. The user must log off now to gain the administrator rights to the system. Once logged back in the (BootOnceTek.vbs) script will copy the (Removerightstek.vbs) script to the startup folder and delete itself from the statup folder.

At this point, the user will be able to install the print drivers and reboot their system.... After rebooting, the system and logging back in, the (removerightstek.vbs) script will remove the user from the local administrators group... The user will still have administrator rights until they logoff or reboot the system so the print drivers should finish installing ( if you are installing hp drivers)..


NOTE::: All 3 scripts need to be saved on the root drive under a folder called tools... C:\tools\, along with the lsrunas.exe and robocopy.exe files.

Script 1 - (Tempaccess.vbs) Give the (Locked) user local Admin rights
' This script will call the LSRUNAS.EXE file to run an application with administrative rights using
' an admin equivalent account named userrunas. The Script pulls the users login credentials And
' adds that user to the local administrator group.....
' The LSRUNAS.EXE file ((MUST)) be placed into the c:Tools\ folder for this
' script to run. If it is not found, the Script will state the installation cannot proceed, please
' contact your system administrator for help with this issue.
'
' Script Created by PYRO777 12/30/2008




On Error Resume Next

' All variables are defines and command paths are set.
Dim objshell, S0, S1, S2, adminacct, objFSO, Spath, Strpath, LSRUNChk, strUser, WshNetwork, objFolder
Dim WshShell, SRobopath, StrRobopath, vbsname

Set objshell = WScript.CreateObject ("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
S0 = " /user:(Create a domain admin and place name here) /password:(Your Password) /domain:CCMC /Command:"
S1 = " /add"
S2 = "\\"
S3 = "/R:5 /W:15 /V /NP"
vbsName = "BootonceTek.vbs"
StrRobopath = WshShell.SpecialFolders("AllUsersStartup") & S2
SRobopath = "C:\Tools\\"
LSRUNChk = "C:\Tools\lsrunas.exe"
strUser = WshNetwork.UserName
Spath = "net localgroup administrators " & strUser & S1
strpath = " /runpath:C:\"
RoboChk = "C:\Tools\robocopy.exe"

adminacct=Msgbox (" You are about to run the User Authorization utility, do you still want to continue ???",36,"PrinterSetup Check")

if adminacct=7 Then

MsgBox "Thank you for using the User Authorization Utility !!!"
Wscript.Quit

Else
LSrunchek()
End If

' ************************************* MAIN PROGRAM *******************************************
' 1.) The first part of this program (LSrunchek) (RobocopyCheckMain) will check to make sure
' that the Lsrunas.exe and the Robocopy.exe files are located in the
' C:\Tools\ folder, if not the script will send out a message
' stating the file is not found and the script will end.
' 2.) Part 2 of this script runs the Lsrunas file to add the locally logged in user to the
' Administrators Group. (a logoff will be required to set the users new rights)
' After adding the user the the Group, robocopy will launch, placing the bootonce.vbe file into the
' startup that will allow the logged in user to start their application installation and Then
' copy the removerights.vbe file to the startup folder. After copying the .vbe file, the
' bootonce.vbe script will delete itself.
' **** Special Feature::: The & CHR(34) is a special script charactor that emulates a " mark ****
' **********************************************************************************************
Sub LSrunchek()

If objFSO.FileExists(LSRUNChk) Then

RobocopyCheckMain()

Else
X=MsgBox("This installation cannot proceed, due to you are missing the LSRunas file, please contact your system administrator for help !!!!")
WScript.Quit
End If

End Sub

Sub RobocopyCheckMain()

If objFSO.FileExists(RoboChk) Then

StartBackup()

Else
X=MsgBox("I am sorry but you not have RoboCopy.exe in the C:\Tools folder, please copy Robocopy.exe to this folder and try again")
WScript.Quit
End If

End Sub



Sub StartBackup()

Call objShell.Run("cmd.exe /c C:\Tools\lsrunas.exe" & S0 & "" & CHR(34) & Spath & CHR(34)& "" & Strpath)
Call objShell.Run("cmd.exe /c C:\Tools\robocopy.exe """ & sRobopath & """ """ & StrRobopath & """ """ & vbsname & """ " & s3)


X=MsgBox("Please Logout of Windows ((DO NOT REBOOT)) and then install your printer drivers !!!!")

End Sub


Script 2 - (BootOnceTek.vbs)Allow the user to reboot after installing the software and then call the 3rd script to remove those users rights on the next reboot.(After calling the 3rd script, this script will delete itself from the Startup folder...

' This script will use Robocopy.exe to copy the removerights.vbe file to the startup folder and
' after the file is copied, delete itself. Main purpose for this is to allow the printer software
' to complete its installation after the system is rebooted. The Removerights.vbs file will Then
' remove the logged in user from the Local Administrators Groups and also delete itself upon its
' completion.
'
' Script Created by Pyro777 12/31/2008




On Error Resume Next

' All variables are defines and command paths are set.
Dim objshell, S2, S3, objFSO, WshShell, SRobopath, StrRobopath, vbsname, strscript, robochk

Set objshell = WScript.CreateObject ("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
S2 = "\\"
S3 = "/R:5 /W:15 /V /NP"
vbsName = "RemoveRightsTEK.vbs"
StrRobopath = WshShell.SpecialFolders("AllUsersStartup") & S2
SRobopath = "C:\Tools\\"
RoboChk = "C:\Tools\robocopy.exe"

RobocopyCheckMain()
' ************************************* MAIN PROGRAM *******************************************
' 1.) The first part of this program(RobocopyCheckMain) will check to make sure
' that the Robocopy.exe file is located in the C:\Tools\ folder,
' if not the script will send out a message stating the file is not found and the script
' will end.
' 2.) Part 2 of this script copies the removerights.vbe file to the startup folder
' and then this script will delete itself
' **********************************************************************************************


Sub RobocopyCheckMain()

If objFSO.FileExists(RoboChk) Then

StartBackup()

Else
X=MsgBox("I am sorry but you not have RoboCopy.exe in the C:\Tools folder, please copy Robocopy.exe to this folder and try again")
WScript.Quit
End If

End Sub



Sub StartBackup()

Call objShell.Run("cmd.exe /c C:\Tools\robocopy.exe """ & sRobopath & """ """ & StrRobopath & """ """ & vbsname & """ " & s3)

End Sub

' *** NOTE::: This portion of the script will wait 5 seconds after the script runs then delete
' this whole script ******
For i = 1 To 5
' Wscript.Echo i
Wscript.Sleep 1000
Next

strScript = Wscript.ScriptFullName
objFSO.DeleteFile(strScript)

Script 3 - (RemoveRightsTEK.vbs) This script will remove the local user from the Local administrators group and then delete itself from the Startup folder.

' This script will remove the current logged in user from the Local Administrator Group, the BootOnce
' script will copy this file into the Startup folder, this file will run once the user has logged
' back in and will remove the Local Administrator rights for this user. The user will remain as
' an administrator until that user logs off or reboots their system again.
'
' Script Created by Pyro777 12/31/2008

On Error Resume Next

' All variables are defines and command paths are set.
Dim objshell, S0, S1, objFSO, Spath, Strpath, LSRUNChk, strUser, WshNetwork, strscript

Set objshell = WScript.CreateObject ("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = WScript.CreateObject("WScript.Network")

S0 = " /user:(Create a domain admin and place name here) /password:(Your Password) /domain:CCMC /Command:"
S1 = " /delete"

LSRUNChk = "C:\Tools\lsrunas.exe"
strUser = WshNetwork.UserName
Spath = "net localgroup administrators " & strUser & S1
strpath = " /runpath:C:\"

LSrunchek ()

' ************************************* MAIN PROGRAM *******************************************
' 1.) The first part of this program (LSrunchek) will check to make sure that the Lsrunas.exe file Is
' located in the C:\Tools\ folder, if not the script will send out a message
' stating the file is not found and the script will end.
' 2.) Part 2 of this script runs the Lsrunas file from a command line window
' **** Special Feature::: The & CHR(34) is a special script charactor that emulates a " mark ****
' **********************************************************************************************
Sub LSrunchek()

If objFSO.FileExists(LSRUNChk) Then

StartBackup()

Else
X=MsgBox("This installation cannot proceed, due to you are missing the LSRunas file, please contact your system administrator for help !!!!")
WScript.Quit
End If

End Sub


Sub StartBackup()

Call objShell.Run("cmd.exe /c C:\Tools\lsrunas.exe" & S0 & "" & CHR(34) & Spath & CHR(34)& "" & Strpath)

End Sub


' *** NOTE::: This portion of the script will wait 5 seconds after the script runs then delete
' this whole script ******
For i = 1 To 5

Wscript.Sleep 1000
Next

strScript = Wscript.ScriptFullName
objFSO.DeleteFile(strScript)


I hope these 3 scripts help you, please let me know what you think or if you have any improvments for this script comments are welcome !!!!!

 
By the Way, I forgot to mention that I have tested this script on Windows 2000, XP and Vista. Because I am using the special folders in the scripts, all operating systems work fine with these scripts !!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top