从XP中的任务调度器转移到Windows7

我正在从XP中的任务调度器转移到Windows7,我正试图更好地理解它。

我有一个位于此位置的N:\Folder1\subFolder1\subFolder2\subFolder3\subFolder4\script.vbs脚本N:\Folder1\subFolder1\subFolder2\subFolder3\subFolder4\script.vbs

这个script.vbs基本上在同一个目录中打开一个excel文件(.xlsm)并在该excel文件中运行一个macros,然后closures该excel文件。 该脚本使用此代码获取它所在的目录strPath = WshShell.CurrentDirectory

macros基本上复制一个csv文件(位于其他地方)的数据,并可能做一些其他的数据处理的东西。

我在不同的文件夹/子文件夹上面这样做了不同数量的时间,所以基本上每个excel文件都有一个文件夹,它也有自己的script.vbs文件。

然后我安排这些脚本在任务调度程序中运行。

在XP中,这是好的,并在脚本计划,并按要求运行。

但现在我正在使用Windows7,希望能够再次安排这些工作。

事实certificate,我必须将每个script.vbs的位置放置在每个时间表的Action选项卡的Start in: (optional) parmae​​ter中。

但是我想知道的是,为什么我必须在每个时间表上做到这一点 ? 我以为我已经在脚本中获取当前的script.vbs目录,或者我错过了一些东西。 任何其他意见/改进欢迎这种方法。

注意:
我不记得在Windows XP中这样做,但也许Windows XP为你做了这个。
我不需要以最高的私有化运行,因为我的密码每3个月就会更改一次

 'need to update WBName & MacroName here as this is fairly generic dim WshShell set WshShell = CreateObject("Wscript.Shell") dim strPath strPath = WshShell.CurrentDirectory 'WScript.echo("For Debugging: strPath") 'WScript.echo(strPath) 'msgbox strPath Dim myExcelWorker Set myExcelWorker = CreateObject("Excel.Application") 'myExcelWorker.Visible = True ' this makes excel visible dim oWorkBook dim WBName WBName = "\ExcelWorkBook.xlsm" 'WB to be opened dim MacroName MacroName = "'" & strpath & WBName & "'!macroName" 'Macro Name to be run 'Write Start+strPath to log file Call WriteLog("Start_XXX",strPath,"var3") 'Write Mid+strPath+WBName to log file Call WriteLog("Mid___XXX",strpath & WBName,"var3") 'open WB for running macro 'set oWorkBook = myExcelWorker.Workbooks.open(strpath & WBName) 'for WB WITHOUT password Set oWorkBook = myExcelWorker.Workbooks.Open(strpath & WBName,,,,"","Password") 'for WB with password 'Write MacroName to log file Call WriteLog("Mid___XXX",MacroName,"var3") myExcelWorker.Run MacroName myExcelWorker.DisplayAlerts = False 'this is required so the WB will save without being prompted oWorkBook.Save oWorkBook.Close myExcelWorker.DisplayAlerts = True ' set it back to true again as it is good practice myExcelWorker.Quit 'Write End to log file Call WriteLog("End___XXX","t2","t3") set oWorkBook = Nothing set myExcelWorker = Nothing set WshShell = Nothing 'sub to write to log file Sub WriteLog(var1, var2, var3) Dim objShell Set objShell = WScript.CreateObject("WScript.Shell") 'Wscript.Echo "VBSStart.vbs is running" Dim ObjFso Dim StrFileName Dim ObjFile Dim FlName 'WScript.Echo var1 & ",,,," & var2 FlName = "TestFile.txt" StrFileName = objShell.CurrentDirectory & "\" & FlName Set ObjFso = CreateObject("Scripting.FileSystemObject") 'Creating a file for writing data set ObjFile = ObjFso.OpenTextFile(StrFileName, 8, True) 'Writing a string into the file ObjFile.WriteLine(var1 & "," & var2 & "," & var3 & "," & now) 'Closing the file ObjFile.Close 'msgbox "near the end..." ' Using Set is mandatory Set objShell = Nothing End Sub 

Solutions Collecting From Web of "从XP中的任务调度器转移到Windows7"