【问题标题】:How to lock the computer after executing an exe file using batch file programming in windows?在windows中使用批处理文件编程执行exe文件后如何锁定计算机?
【发布时间】:2013-10-03 15:46:56
【问题描述】:

我有一个类似的批处理文件程序。

@echo off
start Mat.exe
>>Need a code here to runand check for termination of "Mat.exe"
rundll32.exe user32.dll, LockWorkStation

>>end of program

如果有人可以帮助我设置程​​序,以便我可以在“Mat.exe”文件终止后立即锁定我的计算机。我真的很感激。提前致谢

【问题讨论】:

    标签: windows batch-file


    【解决方案1】:

    只需在Mat.exe 之前删除start,这样您的批处理文件就会等到Mat.exe 完成。

    编辑:这仅适用于您的 Mat.exe 在控制台或类似设备中运行。 如果删除start 不起作用,您可能需要检查是否Mat.exe 仍在运行。为此,我找到了一个非常有用的帖子,它应该对你有用:How to wait for a process to terminate to execute another process in batch file

    Edit2:完整代码:

    @echo off
    :LOOP
    start Mat.exe
    TASKLIST 2>&1 | find "Mat.exe" > nul
    IF ERRORLEVEL 1 (
      rundll32.exe user32.dll, LockWorkStation
    ) ELSE (
      SLEEP 3
      GOTO LOOP
    )
    

    您可以随意调整SLEEP,但我建议至少使用 1 秒,否则您将获得 100% 的使用率。

    【讨论】:

    • 一点用都没有,我需要运行我制作的 OpenGL exe 文件。我需要在计算机终止后立即锁定它。如果我不使用“启动”命令,我什至如何让 exe 文件启动?
    • 只需输入一个有效的文件名即可启动程序,启动命令会打开一个新窗口以在其中运行程序,因此批处理文件不会阻止它的执行。
    【解决方案2】:

    尝试使用带有 /Wait 开关的 Start 命令。这是一个例子:

    @echo off 
    REM //start Mat.exe
    start /wait [path of Mat.exe]
    rundll32.exe user32.dll, LockWorkStation
    

    记得使用 8.3 的文件名,不要在路径字符串中包含 (" ")

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-27
      • 1970-01-01
      • 2010-10-27
      • 2012-07-28
      • 1970-01-01
      • 1970-01-01
      • 2019-08-29
      • 1970-01-01
      相关资源
      最近更新 更多