首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CMD、DevCon和

CMD、DevCon和
EN

Stack Overflow用户
提问于 2015-11-19 15:42:11
回答 1查看 254关注 0票数 0

我使用DevCon创建了一个DevCon文件,用于重新启动设备,并在运行时正常工作。当我尝试使用run命令在VFP表单中运行相同的文件时,单击它会显示DevCon是不被识别的。

好了!cmd /c "C:\Windows\System32\restart.bat“

好了!"C:\Windows\System32\restart.bat“

我尝试过将Sistem32作为启动路径和启动默认路径,但两者都不起作用。在这个过程中,CMD似乎被搞糊涂了。提前感谢您的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-19 16:25:15

相反,我会尝试使用ShellExecute API。ie:

代码语言:javascript
复制
#Define SW_HIDE             0
#Define SW_NORMAL           1
#Define SW_SHOWMINIMIZED    2
#Define SW_SHOWMAXIMIZED    3

Local lcResult
lcResult = ShellExec('C:\Windows\System32\restart.bat', '', 'C:\Windows\System32', SW_NORMAL)
If !Empty(m.lcResult) && error
    Messagebox(m.lcResult)
Endif

Function ShellExec
    Lparameters tcExecutable,tcParams,tcWorkingDir,tnShowType,tcOperation

    Declare Long ShellExecute In "shell32.dll" ;
        long HWnd, String lpszOp, ;
        string lpszFile, String lpszParams, ;
        string lpszDir, Long nShowCmd
    tcOperation  = Iif(Empty(m.tcOperation), 'Open', m.tcOperation)
    tcExecutable = Iif(Empty(m.tcExecutable), '', m.tcExecutable)
    tcParams     = Iif(Empty(m.tcParams), '', m.tcParams)
    tcWorkingDir = Iif(Empty(m.tcWorkingDir), '', m.tcWorkingDir)
    tnShowType   = Iif(Type('m.tnShowType') # 'N', SW_SHOWNORMAL, m.tnShowType)
    Local lnResult, lcError
    lcError = ''
    lnResult = ShellExecute(0,m.tcOperation,m.tcExecutable,m.tcParams,m.tcWorkingDir,m.tnShowType)
    If !( m.lnResult > 32 ) && Error
        lcError = GetShExecErrorMsg(m.lnResult)
    Endif
    Return m.lcError
Endfunc

Function GetShExecErrorMsg
    Lparameters tnErrNum
    Local Array aErrors[1]
    Local lcMessage, lcErrors,lnErrors,ix

    TEXT to m.lcErrors noshow
0,The operating system is out of memory or resources. \n
2,The specified file was not found. \n
3,The specified path was not found. \n
11,The .exe file is invalid (non-Win32® .exe or error in .exe image). \n
5,The operating system denied access to the specified file.  \n
27,The file name association is incomplete or invalid. \n
30,The DDE transaction could not be completed because
other DDE transactions were being processed. \n
29,The DDE transaction failed. \n
28,The DDE transaction could not be completed because the request timed out. \n
32,The specified dynamic-link library was not found.  \n
31,There is no application associated with the given file name extension.
This error will also be returned if you attempt to print a file that is not printable. \n
8,There was not enough memory to complete the operation. \n
26,A sharing violation occurred. \n
    ENDTEXT
    Clear
    lnErrors = Alines(aErrors,m.lcErrors,.T.,'\n')
    For ix=1 To m.lnErrors
        If ( Val(Chrtran(Left(aErrors[m.ix],;
                At(',',aErrors[m.ix])-1),Chr(13)+Chr(10),'')) = m.tnErrNum )
            lcMessage = Substr(aErrors[m.ix],At(',',aErrors[m.ix])+1)
            Exit
        Endif
    Endfor
    If Empty(m.lcMessage)
        lcMessage = 'An unspecified error occurred.'
    Endif
    Return m.lcMessage
Endfunc
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33808300

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档