from:http://hi.baidu.com/lzycsd/blog/item/60ac860fce5fe0e7ab6457d5.html
在网上搜了搜大部分是这个方法
但是我发现在pb9中可以用,在pb11中不可以用
又查了查 原因是字符问题
把下面例子中的CreateProcessA换成 CreateProcessW即可
createprocess,createprocessA,createprocessW的区别见 http://hi.baidu.com/lzycsd/blog/item/41ef76e7224d3424b93820cd.html
CreateProcess api的用法见
http://hi.baidu.com/lzycsd/blog/item/204f730f388dcc206059f3e6.html
返回错误码见
http://hi.baidu.com/lzycsd/blog/item/54053f95be1119027bf4801c.html
pb调用其他程序总结
Function ULONG GetLastError() Library "KERNEL32.DLL"
STRING lpCommandLine, &
ULONG lpProcessAttributes, &
ULONG lpThreadAttributes, &
BOOLEAN bInheritHandles, &
ULONG dwCreationFlags, &
ULONG lpEnvironment, &
ULONG lpCurrentDirectory, &
REF STARTUPINFO lpStartupInfo, &
REF PROCESS_INFORMATION lpProcessInformation ) &
LIBRARY "KERNEL32.DLL" Alias for "CreateProcessA"
FUNCTION ulong WaitForSingleObject(ulong hHandle,ulong dwMilliseconds) LIBRARY "kernel32.dll"
unsignedlong cb
unsignedlong lpreserved
unsignedlong lpdesktop
unsignedlong lptitle
unsignedlong dwx
unsignedlong dwy
unsignedlong dwxsize
unsignedlong dwysize
unsignedlong dwxcountchars
unsignedlong dwycountchars
unsignedlong dwfillattribute
unsignedlong dwflags
unsignedlong wshowwindow
unsignedlong cbreserved2
unsignedlong lpreserved2
unsignedlong hstdinput
unsignedlong hstdoutput
unsignedlong hstderror
end type
long hprocess
long hthread
unsignedlong dwprocessid
unsignedlong dwthreadid
end type
// 事件: nvo_ftp.Properties - nvo_ftp inherited from nonvisualobject()
//--------------------------------------------------------------------
// 描述:
//--------------------------------------------------------------------
// 参数:
// value string as_executable 执行命令
// value string as_commandparm 命令参数
// value boolean ab_yield 等待返回时,是否释放cpu
// value boolean ab_show 是否显示执行窗口
//--------------------------------------------------------------------
// 举例:
// create_process_wait(ls_command,ls_comm_para,TRUE,FALSE)
//--------------------------------------------------------------------
// 返回: (none)
//--------------------------------------------------------------------
// 作者: Joshua Zou 日期: 2008年02月18日
//--------------------------------------------------------------------
// Copyright (c) 2002-2007 , All rights reserved.
//--------------------------------------------------------------------
// 修改历史:
//
//====================================================================
STARTUPINFO sinfo
PROCESS_INFORMATION pinfo
sinfo.lpReserved = 0 // NULL
sinfo.lpDesktop = 0 // NULL
sinfo.lpTitle = 0 // NULL
sinfo.dwX = 0
sinfo.dwY = 0
sinfo.dwXSize = 0
sinfo.dwYSize = 0
sinfo.dwXCountChars = 0
sinfo.dwYCountChars = 0
sinfo.dwFillAttribute = 0
sinfo.dwFlags = 1
IF ab_show THEN
sinfo.wShowWindow = SW_NORMAL
ELSE
sinfo.wShowWindow = SW_HIDE // 默认隐藏执行窗口
END IF
sinfo.lpReserved2 = 0
sinfo.hStdInput = 0
sinfo.hStdOutput = 0
sinfo.hStdError = 0
bRet = CreateProcess(as_executable,as_executable + " " + as_commandparm,0,0,False,32,0,0,sinfo,pinfo)
//bRet = CreateProcess(NULL,cmd,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&TStartupInfo,&TProcessInformation);
MessageBox("警告", "创建子进程错误,错误码:"+String(GetLastError()))
RETURN False
END IF
DO
// 等待结束
WaitForSingleObject(pinfo.hProcess,0)
bRet = GetExitCodeProcess ( pinfo.hProcess, lpExitCode )
IF ab_yield THEN Yield() //等待返回循环中,释放cpu
LOOP Until ( bRet = True And lpExitCode <> 259 )
ls_comm_para= " a " +as_targetpath+'\'+as_targetfile +" "+as_sourcefile
if create_process_wait(ls_command,ls_comm_para,true,FALSE) = TRUE then
return TRUE
else
return FALSE // 生成压缩文件失败
end if