Sign in with
Sign up | Sign in
Your question

My vbs don't work using AD

  • Programming
  • VBS
  • Active Directory
  • Printers
  • Apps
Last response: in Apps General Discussion
May 6, 2010 8:46:16 AM

Hello, i apologize for my English.
my problem is than i have write a vbs which add or remove printers on local machine but when I'm hosted that on my active directory this script don't apply when a user log on on machine.
someone can help me.

More about : vbs work

May 6, 2010 8:17:14 PM

Can you post the text of the vbs script?
a b L Programming
May 6, 2010 9:14:39 PM

Are you trying to run the script locally on each computer, or through some group policy in the AD?
Related resources
May 7, 2010 7:17:52 AM

Yes, my script is successful run locally. the problem is when i try to apply that using AD.
here my script:

PrnName = "Kyocera FS-1100 KX"
Set objWshShell = WScript.CreateObject("WScript.Shell")

'retrieve username and computername
strComputer = objWshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
strUserName = objWshShell.ExpandEnvironmentStrings("%username%")
strHome = objWshShell.ExpandEnvironmentStrings("%HOMEPATH%")
strDrive = objWshShell.ExpandEnvironmentStrings("%HOMEDRIVE%")

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True

Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")

Set dr = objWMIService.ExecQuery("Select * from Win32_Printer where DeviceID = 'Kyocera FS-1100 KX'")

Set fs = CreateObject("Scripting.FileSystemObject")
folder = strDrive & strHome

if fs.FolderExists(folder) and dr.Count <> 0 then
For Each objPrinter in colInstalledPrinters
if objPrinter.DeviceID = PrnName then
end if
'if fs.FolderExists(folder) and dr.Count = 0 then
'For Each objPrinter in colInstalledPrinters
'end if

if (fs.FolderExists(folder)) and (dr.Count = 0 or colInstalledPrinters.Count = 0) then
' Add a l'imprimante
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
objPrinter.DriverName = PrnName
objPrinter.PortName = "USB001"
objPrinter.DeviceID = PrnName
objPrinter.Location = "Imprimante installée sur la machine " & strComputer
objPrinter.Comment = "Imprimante " & PrnName
objPrinter.Network = False
end if

For Each objPrinter in colInstalledPrinters
if objPrinter.DeviceID = "Microsoft XPS Document Writer" or objPrinter.DeviceID = "PDF4U Adobe Creator" or objPrinter.DeviceID = "Microsoft Office Document Image Writer" then
end if

' restart spooler

Set objSpoolerSvc = objWMIService.Get("Win32_Service.Name='spooler'")
iReturn = objSpoolerSvc.StopService()
iReturn = objSpoolerSvc.StartService()

end if

'For Each User In objlocal
'If lcase(User.Name) = lcase(strUserName) Then
'Set objUser = GetObject("WinNT://" & strComputer & "/username, " & strUserName)

'msgbox User.Name & " already exists." & vbCrLf & "The password was re-set."
'End If
'End Sub

'strCommand = "rundll32 printui.dll,PrintUIEntry /y /n Kyocera FS-1100 KX /f /r USB001"
'intResult = ("rundll32 printui.dll,PrintUIEntry /p /n Kyocera FS-1100 KX" , 0, true)

May 7, 2010 8:32:06 AM

All right, I'm working on it now, plus I posted the question and the script on a couple other sites. I'll let you know the results.
a b L Programming
May 7, 2010 2:05:03 PM

Have you ran gpupdate on any of the clients after setting the script to run on the domain controller? How specifically did you set the script up to run on the domain controller?
May 8, 2010 3:42:35 AM

Have you installed Group Policy Preferences? Someone at suggested that, and highly recommended it. Works on XP and higher, but you have to have the authority to do so.

Also, what Operating System are you running, and what is your server?
May 10, 2010 7:47:47 AM

Hi, My Client using XP and my server 2003 server.
I try to apply my script on OU where i put users accounts only and apparently something changed when i log in (I do Gpupdate before).
May 10, 2010 8:40:16 AM

I gotta be honest with you, I can't figure it out. I only got one recommendation on one of the other sites I posted it to, and that was my previous post. Sorry.

From what I can tell it should work, but I've never tried anything with printers in vbs or any language for that matter. I hope someone can help you, but I really don't know what the problem is.
May 10, 2010 9:20:25 AM

Ok! No problem. Thanks Anyway!!