【问题标题】:How to make the operation by hand into autorun script?如何将手动操作变成自动运行脚本?
【发布时间】:2016-03-27 02:03:14
【问题描述】:

我想在win7中将手动操作变成自动运行脚本。 我的操作:
step1 以管理员身份登录cmd控制台运行命令。

D:\wamp\wampmanager.exe

step2 在cmd控制台输入超时命令。

timeout  10

step3 将数据加载到我的 wordpress 数据库中

mysql -u root -ppasswd wpdatabase < e:/back.sql 

现在我将命令写成 start.bat 并保存在启动目录中。

D:\wamp\wampmanager.exe
timeout  10
mysql -u root -ppasswd wpdatabase < e:/back.sql 

没有效果。

重要的是让start.bat以管理员身份运行,如何在启动阶段自动以管理员身份运行start.bat?如何解决?

【问题讨论】:

    标签: batch-file cmd windows-7 autorun


    【解决方案1】:

    这是一个 vbscript,它允许在 shell 对象(如文件)上运行右键单击命令。双击它以获取帮助。


    Windows 脚本宿主


    ShVerb

    在文件或文件夹上列出或运行资源管理器动词(右键菜单)

    ShVerb &lt;filename&gt; [verb]

    不使用动词时列出文件或文件夹可用的动词

    程序列出了大多数动词,但只列出了第一个分隔符上方的动词

    以这种方式使用时菜单的工作原理

    可以使用属性动词。但是程序必须继续运行

    保持属性对话框打开。它通过显示继续运行

    一个消息框。


    好的


    HelpMsg = vbcrlf & "  ShVerb" & vbcrlf & vbcrlf & "  David Candy 2014" & vbcrlf & vbcrlf & "  Lists or runs an explorer verb (right click menu) on a file or folder" & vbcrlf  & vbcrlf & "    ShVerb <filename> [verb]" & vbcrlf & vbcrlf & "  Used without a verb it lists the verbs available for the file or folder" & vbcrlf & vbcrlf
    HelpMsg = HelpMsg & "  The program lists most verbs but only ones above the first separator" & vbcrlf & "  of the menu work when used this way" & vbcrlf & vbcrlf 
    HelpMsg = HelpMsg & "  The Properties verb can be used. However the program has to keep running" & vbcrlf & "  to hold the properties dialog open. It keeps running by displaying" & vbcrlf & "  a message box." 
    Set objShell = CreateObject("Shell.Application")
    Set Ag = WScript.Arguments 
    set WshShell = WScript.CreateObject("WScript.Shell") 
    Set fso = CreateObject("Scripting.FileSystemObject")
    
        If Ag.count = 0 then 
            wscript.echo "  ShVerb - No file specified"
            wscript.echo HelpMsg 
            wscript.quit
        Else If Ag.count = 1 then 
            If LCase(Replace(Ag(0),"-", "/")) = "/h" or Replace(Ag(0),"-", "/") = "/?" then 
                wscript.echo HelpMsg 
                wscript.quit
            End If
        ElseIf Ag.count > 2 then 
            wscript.echo vbcrlf & "  ShVerb - To many parameters" & vbcrlf & "  Use quotes around filenames and verbs containing spaces"  & vbcrlf
            wscript.echo HelpMsg 
            wscript.quit
        End If
    
        If fso.DriveExists(Ag(0)) = True then
            Set objFolder = objShell.Namespace(fso.GetFileName(Ag(0)))
    '       Set objFolderItem = objFolder.ParseName(fso.GetFileName(Ag(0)))
            Set objFolderItem = objFolder.self
            msgbox ag(0)
        ElseIf fso.FolderExists(Ag(0)) = True then
            Set objFolder = objShell.Namespace(fso.GetParentFolderName(Ag(0)))
            Set objFolderItem = objFolder.ParseName(fso.GetFileName(Ag(0)))
        ElseIf fso.fileExists(Ag(0)) = True then
            Set objFolder = objShell.Namespace(fso.GetParentFolderName(Ag(0)))
            Set objFolderItem = objFolder.ParseName(fso.GetFileName(Ag(0)))
        Else
            wscript.echo "  ShVerb - " & Ag(0) & " not found"
            wscript.echo HelpMsg 
            wscript.quit
        End If
    
        Set objVerbs = objFolderItem.Verbs
    
        'If only one argument list verbs for that item
    
        If Ag.count = 1 then
            For Each cmd in objFolderItem.Verbs
                If len(cmd) <> 0 then CmdList = CmdList & vbcrlf & replace(cmd.name, "&", "") 
            Next
            wscript.echo mid(CmdList, 2)
    
        'If two arguments do verbs for that item
    
        ElseIf Ag.count = 2 then
            For Each cmd in objFolderItem.Verbs
                If lcase(replace(cmd, "&", "")) = LCase(Ag(1)) then 
                    wscript.echo(Cmd.doit)
                    Exit For
                End If
            Next
        'Properties is special cased. Script has to stay running for Properties dialog to show.
            If Lcase(Ag(1)) = "properties" then
                WSHShell.AppActivate(ObjFolderItem.Name & " Properties")
                msgbox "This message box has to stay open to keep the " & ObjFolderItem.Name & " Properties dialog open."
            End If  
        End If
    End If
    

    【讨论】:

      【解决方案2】:

      你是说d:\wamp... 导致脚本以管理员身份运行吗?

      已经有很多关于 SO 的文章概述了如何以管理员身份运行脚本。

      您的问题可能是您正在尝试运行start.bat - 尝试将其重命名为startmysql.bat,因为start 是一个内部cmd 命令。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-10
        • 2023-02-11
        • 2017-07-21
        • 1970-01-01
        相关资源
        最近更新 更多