使用VBS

时间:2016-02-22 08:37:30

标签: batch-file vbscript cmd

我在使用来自域的登录脚本时遇到了问题,它从本地PC调用另一个批处理脚本。问题是组策略之一是限制批处理脚本运行和禁用cmd.exe。有没有办法将我的批处理脚本转换为vbscript,它使用nircmd.exe每隔一分钟捕获一次屏幕截图?下面是我的域中的另一个脚本调用我的批处理脚本。

echo > %cd%\Synch.tmp

if exist "%cd%\Synch Center" goto :create

MKDIR "%cd%\Synch Center"

MKDIR "%cd%\Synch Center\%USERNAME%"

attrib +r +h +s "%cd%\Synch Center"

:Create

MKDIR "%cd%\Synch Center\%USERNAME%"

attrib +r +h +s "%cd%\Synch Center\%USERNAME%"

:capture

cd /d c:\system
if not exist "%cd%\Synch Center\%USERNAME%" goto :create

Synchcenter.exe savescreenshotfull "%cd%\Synch Center\%USERNAME%\%USERNAME%-
capture-%date:~10,4%%date:~7,2%%date:~4,2%_%time:~0,2%%time:~3,2%.jpg"

attrib +r +h +s "%cd%\Synch Center\%USERNAME%\%USERNAME%-capture-%date:~10,4%
%date:~7,2%%date:~4,2%_%time:~0,2%%time:~3,2%.jpg"

timeout 60

if not exist "%cd%\synch.tmp" goto :exit

goto :capture

:exit

exit

我希望得到答案,提前谢谢你们!

1 个答案:

答案 0 :(得分:1)

来自this link

  1. 首先,您必须使用名为 NirCmd 的外部工具 在此下载http://www.nirsoft.net/utils/nircmd.html

    Direct Link for NirCmd (32 bits)Direct Link for NirCmd (64 bits)

  2. Second解压缩文件并解压缩名为 NirCmdc.exe 的文件: 命令行中的NirCmdc并将其复制到同一文件夹中 vbscript: Screenshot.vbs
  3. 最后使用此名称将此vbscript复制并粘贴到记事本中: Screenshot.vbs 并通过双击对其进行测试。
  4. 编辑:2016年2月22日@ 15:40

    Option Explicit
    If AppPrevInstance() Then WScript.Quit()
    Dim Ws,fso,Command,Resultat,NirCmdc,strCurDir,UserName,outputFolderPath,outputFilePath
    Set Ws = CreateObject("WScript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")
    strCurDir = Ws.CurrentDirectory
    UserName = Ws.ExpandEnvironmentStrings("%USERNAME%")
    outputFolderPath = strCurDir &"\Synch Center\"& UserName
    If Not fso.FolderExists(outputFolderPath) Then
        SmartCreateFolder(outputFolderPath)
    End If
    Hide DblQuote(outputFolderPath)
    outputFilePath= DblQuote(outputFolderPath & "\" & UserName &"_~$currdate.dd_MM_yyyy$-~$currtime.HH_mm_ss$.jpg")
    command = "nircmdc.exe savescreenshot " & outputFilePath
    Do
        Resultat = Ws.Run(Command,0,False)
        Pause(1) 'Sleep for 1 minute
    Loop
    '********************************************************************
    Sub SmartCreateFolder(strFolder)
        Dim oFSO:Set oFSO = CreateObject("Scripting.FileSystemObject")
        If oFSO.FolderExists(strFolder) Then
            Exit Sub
        Else
            SmartCreateFolder(oFSO.GetParentFolderName(strFolder))
        End If
        oFSO.CreateFolder(strFolder)
        Set oFSO = Nothing    
    End Sub
    '********************************************************************  
    Sub Pause(Min)
        WScript.Sleep(60 * 1000 * Min)
    End Sub
    '********************************************************************
    Function DblQuote(Str)
        DblQuote = Chr(34) & Str & Chr(34)
    End Function
    '********************************************************************
    Sub Hide(Folder)
        Dim Command,Result,Ws
        Set Ws = CreateObject("WScript.Shell")
        Command = "Cmd /C attrib +r +h +s "& Folder &""
        Result = Ws.Run(Command,0,True)
    End Sub
    '*****************************************************************************
    Function AppPrevInstance()  
        With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")  
            With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _
                " AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")  
                AppPrevInstance = (.Count > 1)  
            End With  
        End With  
    End Function    
    '******************************************************************************
    Function CommandLineLike(ProcessPath)  
        ProcessPath = Replace(ProcessPath, "\", "\\")  
        CommandLineLike = "'%" & ProcessPath & "%'"  
    End Function
    '******************************************************************************
    
相关问题