c语言中怎么调用系统中的可执行文件

c语言中怎么调用系统中的可执行文件,第1张

参考一下吧

#include <stdlib.h>

int system ( const char * command )

system() 函数用于执行 *** 作系统系统命令(e.g. after cmd in windows)以及当前安装的可执行程序

for example:

system ("dir")

system ("pc para1 para2")

不同的 *** 作系统有不同的命令集

而当前的可执行程序集和你的具体安装有关

用在c++中,包含头文件<stdlib.h>

然后直接system ("...")or system (str.c_str())

/* system example : DIR */

#include <stdio.h>

#include <stdlib.h>

int main ()

{

int i

printf ("Checking if processor is available...")

if (system(NULL)) puts ("Ok")

else exit (1)

printf ("Executing command DIR...\n")

i=system ("dir")

printf ("The value returned was: %d.\n",i)

return 0

}

void CAdoDlg::OnBnClickedOk()

{

ShellExecute(NULL,"open","C:\\WINDOWS\\system32\\mstsc.exe",NULL,NULL,SW_SHOW)

Sleep(500)

CWnd *pMainWnd = FindWindow(NULL,"远程桌面连接")

HWND hMainWnd = pMainWnd->m_hWnd

HWND hOptionWnd = ::FindWindowEx(hMainWnd,NULL,"Button","选项(&O) >>")

::SendMessage(hOptionWnd,BM_CLICK,0,0)

HWND hDlgWnd = ::FindWindowEx(hMainWnd,NULL,"#32770","")

if ( hDlgWnd == NULL )

{

MessageBox("未找到远程桌面连接上的dialog!")

return

}

HWND hComputerIPWnd = ::FindWindowEx(hDlgWnd,NULL,"ComboBoxEx32",NULL)

if ( hComputerIPWnd == NULL )

{

MessageBox("未找到填写远程计算机IP地址的窗口!")

return

}

HWND hComputerUserNameWnd = ::FindWindowEx(hDlgWnd,NULL,"Edit",NULL)

if ( hComputerUserNameWnd == NULL)

{

MessageBox("未找到填写远程计算机用户名的窗口!")

return

}

HWND hComputerUserPwdWnd = ::FindWindowEx(hDlgWnd,hComputerUserNameWnd,"Edit",NULL)

if ( hComputerUserPwdWnd == NULL )

{

MessageBox("未找到填写远程计算机用户密码的窗口!")

return

}

intnLen=m_servip.GetLength()

char* servip=new char[nLen]

strcpy(servip,m_servip)

char* pt=servip

intlongth=1

while(*pt++!=' ')

{

longth++

continue

}

pt--

for(int i=longthi<=nLeni++)

{

strcpy(pt,'\0')

pt++

}

/*nLen=m_servuser.GetLength()

char* servuser=new char[nLen]

strcpy(servuser,m_servuser)

nLen=m_servpwd.GetLength()

char* servpwd=new char[nLen]

strcpy(servpwd,m_servpwd)*/

::SendMessage(hComputerIPWnd,WM_SETTEXT,0,(LPARAM)servip)

//::SendMessage(hComputerUserNameWnd,WM_SETTEXT,0,(LPARAM)servuser)

//::SendMessage(hComputerUserPwdWnd,WM_SETTEXT,0,(LPARAM)servpwd)

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/8139333.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存