douji1853 2016-02-11 10:04
浏览 323

使用golang的CreateProcess

Hello I am try to call CreateProcess from syscall

func CreateProcess(appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) 

But I got error num 123 ("The filename, directory name, or volume label syntax is incorrect."), The path of the calc.exe is correct.

package main
import (
        "fmt"
        "syscall"
)

func main() {
    var pS syscall.SecurityAttributes
    var tS syscall.SecurityAttributes
    var iH bool = true
    var cF uint32
    var env uint16
    var cD uint16
    var sI syscall.StartupInfo
    var pI syscall.ProccessInformation
    var err error

    err = syscall.CreateProcess(
        syscall.StringToUTF16Ptr("c:\\windows\\system32\\calc.exe"),
        syscall.StringToUTF16Ptr(""),
        &pS,
        &tS,
        iH,
        cF,
        &env,
        &cD,
        &sI,
        &pI)

        fmt.Printf("Return: %d
", err)
}
  • 写回答

1条回答 默认 最新

  • dqp4933 2016-02-11 16:39
    关注

    You incorrectly set parameter lpCurrentDirectory(from https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx) :

    The full path to the current directory for the process. The string can also specify a UNC path. If this parameter is NULL, the new process will have the same current drive and directory as the calling process. (This feature is provided primarily for shells that need to start an application and specify its initial drive and working directory.)

    If you make it nil, then it will work. However, if to take for a sample example from this, then your code can be rewritten as:

    package main
    
    import (
        "fmt"
        "syscall"
    )
    
    func main() {
    
        var sI syscall.StartupInfo
        var pI syscall.ProcessInformation
    
        argv := syscall.StringToUTF16Ptr("c:\\windows\\system32\\calc.exe")
    
        err := syscall.CreateProcess(
            nil,
            argv,
            nil,
            nil,
            true,
            0,
            nil,
            nil,
            &sI,
            &pI)
    
        fmt.Printf("Return: %d
    ", err)
    } 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64