关于Visual Studio 2008 环境变量的配置 100
我想在cmd里面运行cl,csc之类的命令,但是不像从Visualstudio2008命令提示进入;在cmd中运行vcvars32.bat以后,可以用,但是关闭cmd后,...
我想在cmd里面运行 cl,csc之类的命令,但是不像从 Visual studio 2008命令提示进入;在cmd中运行vcvars32.bat以后,可以用,但是关闭cmd后,要重新运行vcvars32.bat。
请问有没有一劳永逸的办法?
回答者: 44498 - 江湖新秀 四级:
这个方法是不行的,毕竟环境变量没设置。
我目前找到的方法:
@echo off
@title 命令提示符
call "D:\Program Files\Microsoft Visual Studio 9.0\VC\bin\"vcvars32.bat
cls
@c:\windows\system32\cmd.exe
把这个bat放到system32中。 展开
请问有没有一劳永逸的办法?
回答者: 44498 - 江湖新秀 四级:
这个方法是不行的,毕竟环境变量没设置。
我目前找到的方法:
@echo off
@title 命令提示符
call "D:\Program Files\Microsoft Visual Studio 9.0\VC\bin\"vcvars32.bat
cls
@c:\windows\system32\cmd.exe
把这个bat放到system32中。 展开
3个回答
展开全部
自己写个程序搞定喽!
请在win32空项目中粘贴下列代码。
#include <windows.h>
//请保证未打开其他命令行窗口,否则可能会有未知错误
void SendCommandMessage(HWND hWnd,char *str)
{
char *p = str;
while(*p != '\0')
{
::SendMessage(hWnd,WM_CHAR,*p,NULL);
p++;
}
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
::ShellExecute(NULL,TEXT("open"),TEXT("cmd.exe"),NULL,NULL,SW_SHOW);
Sleep(500);
HWND hWnd = ::FindWindow(TEXT("ConsoleWindowClass"),NULL);
if(!hWnd)
{
MessageBox(NULL,TEXT("未找到命令行窗口!"),NULL,MB_OK);
return 0;
}
char *str = "vcvars32.bat";
SendCommandMessage(hWnd,str);
SendMessage(hWnd,WM_CHAR,VK_RETURN,NULL);
//可继续发送多个命令……
/*
char *str1 = "command1.bat";
SendCommandMessage(hWnd,str1);
SendMessage(hWnd,WM_CHAR,VK_RETURN,NULL);
char *str2 = "command2.bat";
SendCommandMessage(hWnd,str1);
SendMessage(hWnd,WM_CHAR,VK_RETURN,NULL);
……
*/
return 0;
}
下面这个不受其他打开的窗口影响。
#include <windows.h>
BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam);
void SendCommandMessage(HWND hWnd,char *str);
PROCESS_INFORMATION pi;
STARTUPINFO si;
HWND g_hWnd = NULL;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
if( !CreateProcess( L"c:\\windows\\system32\\cmd.exe", // No module name (use command line)
NULL, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
MessageBox(NULL,L"CREATE PROCESS FAILED!",NULL,MB_OK);
return 0;
}
Sleep(500);//必须睡眠一段时间否则可能枚举不到新创建的进程
::EnumWindows(EnumWindowsProc,NULL);
HWND hWnd = g_hWnd;
if(!hWnd)
{
MessageBox(NULL,TEXT("未找到命令行窗口!"),NULL,MB_OK);
return 0;
}
char *str = "vcvars32.bat";
SendCommandMessage(hWnd,str);
SendMessage(hWnd,WM_CHAR,VK_RETURN,NULL);
/*
char *str1 = "command1.bat";
SendCommandMessage(hWnd,str1);
SendMessage(hWnd,WM_CHAR,VK_RETURN,NULL);
char *str2 = "command2.bat";
SendCommandMessage(hWnd,str1);
SendMessage(hWnd,WM_CHAR,VK_RETURN,NULL);
……
*/
return 0;
}
void SendCommandMessage(HWND hWnd,char *str)
{
char *p = str;
while(*p != '\0')
{
::SendMessage(hWnd,WM_CHAR,*p,NULL);
p++;
}
}
BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam)
{
DWORD dwID;
GetWindowThreadProcessId(hwnd,&dwID);
if(pi.dwProcessId == dwID)
{
g_hWnd = hwnd;
return FALSE;
}
return TRUE;
}
请在win32空项目中粘贴下列代码。
#include <windows.h>
//请保证未打开其他命令行窗口,否则可能会有未知错误
void SendCommandMessage(HWND hWnd,char *str)
{
char *p = str;
while(*p != '\0')
{
::SendMessage(hWnd,WM_CHAR,*p,NULL);
p++;
}
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
::ShellExecute(NULL,TEXT("open"),TEXT("cmd.exe"),NULL,NULL,SW_SHOW);
Sleep(500);
HWND hWnd = ::FindWindow(TEXT("ConsoleWindowClass"),NULL);
if(!hWnd)
{
MessageBox(NULL,TEXT("未找到命令行窗口!"),NULL,MB_OK);
return 0;
}
char *str = "vcvars32.bat";
SendCommandMessage(hWnd,str);
SendMessage(hWnd,WM_CHAR,VK_RETURN,NULL);
//可继续发送多个命令……
/*
char *str1 = "command1.bat";
SendCommandMessage(hWnd,str1);
SendMessage(hWnd,WM_CHAR,VK_RETURN,NULL);
char *str2 = "command2.bat";
SendCommandMessage(hWnd,str1);
SendMessage(hWnd,WM_CHAR,VK_RETURN,NULL);
……
*/
return 0;
}
下面这个不受其他打开的窗口影响。
#include <windows.h>
BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam);
void SendCommandMessage(HWND hWnd,char *str);
PROCESS_INFORMATION pi;
STARTUPINFO si;
HWND g_hWnd = NULL;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
if( !CreateProcess( L"c:\\windows\\system32\\cmd.exe", // No module name (use command line)
NULL, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
MessageBox(NULL,L"CREATE PROCESS FAILED!",NULL,MB_OK);
return 0;
}
Sleep(500);//必须睡眠一段时间否则可能枚举不到新创建的进程
::EnumWindows(EnumWindowsProc,NULL);
HWND hWnd = g_hWnd;
if(!hWnd)
{
MessageBox(NULL,TEXT("未找到命令行窗口!"),NULL,MB_OK);
return 0;
}
char *str = "vcvars32.bat";
SendCommandMessage(hWnd,str);
SendMessage(hWnd,WM_CHAR,VK_RETURN,NULL);
/*
char *str1 = "command1.bat";
SendCommandMessage(hWnd,str1);
SendMessage(hWnd,WM_CHAR,VK_RETURN,NULL);
char *str2 = "command2.bat";
SendCommandMessage(hWnd,str1);
SendMessage(hWnd,WM_CHAR,VK_RETURN,NULL);
……
*/
return 0;
}
void SendCommandMessage(HWND hWnd,char *str)
{
char *p = str;
while(*p != '\0')
{
::SendMessage(hWnd,WM_CHAR,*p,NULL);
p++;
}
}
BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam)
{
DWORD dwID;
GetWindowThreadProcessId(hwnd,&dwID);
if(pi.dwProcessId == dwID)
{
g_hWnd = hwnd;
return FALSE;
}
return TRUE;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
如果你不嫌麻烦,非要用CMD去运行csc的话,
你就把CSC拷贝到system32目录下吧。
你就把CSC拷贝到system32目录下吧。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
安装的时候环境变量软件已经帮你设置好了的,如果你要用其他的库,可以再改环境变量。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询