IcemanND Posted December 20, 2007 Posted December 20, 2007 you could create the task from a vbscript.You could you your CMD file or run bginfo directly and just have the switches set in the task. This will check for the existence of a scheduled task that has bginfo.exe in the task first before creating a new one so you don't end up with multiples. As configured it runs every morning at 3 am.option explicitconst EVENT_SUCCESS = 0const EVENT_ERROR = 1const EveryDay = 127Dim BGINFODim strComputer,objWMIServiceptrBGINFO = falseptrSpyBot = falseptrSpyBotUpdate = false'if not used as a startup script replace . with desired computernamestrComputer = "."Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")GetCurrentJobsScheduleSpywareTaskswscript.quitSub ScheduleSpywareTasks Dim errJobCreated, ScheduleErrors, objNewJob, JobID On Error Resume Next ScheduleErrors = False Set objNewJob = objWMIService.Get("Win32_ScheduledJob") if ptrBGINFO = false then 'replace BGINFO SWITCHES with your desired switches, be sure to leave a space in front of the first switch. Also change the path to BGINFO. errJobCreated = objNewJob.Create (Chr(34) & "\\mydomain\netlogon\bginfo.exe" & Chr(34) & " BGINFO SWITCHES", "********000000.000000" & TimeZoneOffset, True , EveryDay, , , JobID) If Err.number <> 0 Then ScheduleErrors = True end if If ScheduleErrors = True Then WshShell.LogEvent EVENT_ERROR, "An error occured trying to schedule BGInfo job" Else WshShell.LogEvent EVENT_SUCCESS, "Scheduling of BGInfo job successful" End IfEnd SubSub GetCurrentJobs 'define variables for use with script Dim objJob, colScheduledJobs 'clear errors On Error Resume Next Set colScheduledJobs = objWMIService.ExecQuery("Select * from Win32_ScheduledJob") For Each objJob in colScheduledJobs if instr(objJob.Command, "bginfo.exe") > 0 then ptrBGINFO = true end if NextEnd SubFunction TimeZoneOffset 'Read time zone offset value from Registry. Dim oShell, TZOffset Set oShell = CreateObject("WScript.Shell") TZOffset = oShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias") TZOffset = Right(1000 + TZOffset, 3) TimeZoneOffset = -TZOffsetEnd Function
Constantine Posted December 20, 2007 Author Posted December 20, 2007 Option ExplicitConst EVENT_SUCCESS = 0Const EVENT_ERROR = 1Const EveryDay = 127Dim BGINFODim strComputer, objWMIServiceDim ptrBGINFODim ptrSpybotDim ptrSpybotUpdateptrBGINFO = FalseptrSpybot = FalseptrSpybotUpdate = False'if not used as a startup script replace . with desired computernamestrComputer = "D0202396"Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")GetCurrentJobsScheduleSpywareTaskswscript.QuitSub ScheduleSpywareTasks() Dim errJobCreated, ScheduleErrors, objNewJob, JobID On Error Resume Next ScheduleErrors = False Set objNewJob = objWMIService.Get("Win32_ScheduledJob") If ptrBGINFO = False Then 'replace BGINFO SWITCHES with your desired switches, be sure to leave a space in front of the first switch. Also change the path to BGINFO. errJobCreated = objNewJob.Create(Chr(34) & "\\mickey\groups\background\bginfo.exe" & Chr(34) & " drh.bgi /timer:0", "********000000.000000" & TimeZoneOffset, True, EveryDay, , , JobID) If Err.Number <> 0 Then ScheduleErrors = True End If If ScheduleErrors = True Then WshShell.LogEvent EVENT_ERROR, "An error occured trying to schedule BGInfo job" Else WshShell.LogEvent EVENT_SUCCESS, "Scheduling of BGInfo job successful" End IfEnd SubSub GetCurrentJobs() 'define variables for use with script Dim objJob, colScheduledJobs 'clear errors On Error Resume Next Set colScheduledJobs = objWMIService.ExecQuery("Select * from Win32_ScheduledJob") For Each objJob In colScheduledJobs If InStr(objJob.Command, "bginfo.exe") > 0 Then ptrBGINFO = True End If NextEnd SubFunction TimeZoneOffset() 'Read time zone offset value from Registry. Dim oShell, TZOffset Set oShell = CreateObject("WScript.Shell") TZOffset = oShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias") TZOffset = Right(1000 + TZOffset, 3) TimeZoneOffset = -TZOffsetEnd FunctionThat is what I had to change to get it to work. Few questions though. I highlighted my changes in bold so their easy to spot incase I'm wrong.1 Why is there SpyBot stuff in the script? This a remodeled script? (If its not doing anything I won't worry about it, just have to ask)2 If I run it off my computer. It works. I can schedule the task on my PC using the "." everything is perfectly okay. If I try to do it on someone elses computer renaming the "." to their "ComputerName" the script works like normal. But it tells me it cannot find the configuration file. Same thing happens if I leave it "." and run it from their PC.Basically no matter how I schedule it, it works on my PC but no one elses.The files are shared on a server with everyone having full control of the folder for trouble shooting purposes. Nothing changes. here is the real tricky part. I can log into any other computer and it fails. But from my system it works.This is why I started using the Batch file to launch it in the first place. I had to use a mapped network drive and the batch file to get rid of the error about the configuration file.
IcemanND Posted December 20, 2007 Posted December 20, 2007 <snip>Dim ptrBGINFODim ptrSpybotDim ptrSpybotUpdateptrBGINFO = FalseptrSpybot = FalseptrSpybotUpdate = False<snip>Sorry, I edited it from a script we use for scheduling spybot and ad-aware.you can delete the ptrSpyBot, and ptrSpybotUpdate lines.The rest looks right.
Constantine Posted December 20, 2007 Author Posted December 20, 2007 Any idea why I get the unable to find configuration error?
IcemanND Posted December 20, 2007 Posted December 20, 2007 put the full path to drh.bgi.\\mickey\groups\background\drh.bgi
eyeball Posted December 20, 2007 Posted December 20, 2007 (edited) Nice one IcemanND! il save that script to play about with sometime, if thats ok Edited December 20, 2007 by eyeball
IcemanND Posted December 20, 2007 Posted December 20, 2007 @Eyeball - have fun with it.@constantine - I think I found the issue. Or at least when I did a full test after a reboot and making sure I had no active network folder connections. When you create a task with either the AT command or my script by default create the task to run as the SYSTEM account which cannot connect to the network location. If I manually create the task or do it with schtasks.exe and specify my domain account it works just fine.the problem with schtasks.exe is that you then either need a generic account to use to connect to it. or copy the files down to the local machines and run it locally.
Constantine Posted December 20, 2007 Author Posted December 20, 2007 So... basically the way I'm doing it with the Login Script is the only option?
IcemanND Posted December 20, 2007 Posted December 20, 2007 if you want it to run from a network share it seems that way, or you have to configure the task to run under a user account.
eyeball Posted December 21, 2007 Posted December 21, 2007 couldnt he just create a new active directory user specifically for running scheduled tasks and have the tasks run with those credentials?im not sure i get why adding it with schtasks.exe and specifying domain admin as the user account wont work or is there some issue with using this account that i am not aware of?
Constantine Posted December 21, 2007 Author Posted December 21, 2007 (edited) Now that I've had time to think about this. How were your permissions set up on your test area? Was it set to Everyone could come in? or mabey just Domain Users?I gave the Everyone group full control just to see what would happen.**EDIT**I should also mention I'm not using the NetLogon folder. I'm just using a shared folder on a server. Edited December 21, 2007 by Constantine
eyeball Posted December 21, 2007 Posted December 21, 2007 on my test setup i was just running a local program c:\windows\system32\mspaint.exe and you want to run a remote one, i guess thats how the 2 setups differ, could you make a script to copy bginfo.bat to each users c: drive and then have the scheduled task run c:\bginfo.bat at scheduled intervals under the domain\administrator account?
Constantine Posted December 21, 2007 Author Posted December 21, 2007 I kind of tried that.That might work, I can get the batch file on each computer.My issue at the time was, that I was unable to create the task to run, mainly because the AT command was not working and just flat out copying the task wasn't working at all. Now that I have learned quite a bit more. I think if I modify his script to create the task to launch the batch file, and also copy the batch file locally. It might actually work, if nothing else schtasks might. I'll try both and let you know what happens.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now