Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Shellexecute and dos (CMD) window
Message
From
25/09/1998 14:33:12
 
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00140918
Message ID:
00140951
Views:
30
>>The following code (borrowed from David Frankenbach and modified) will map a drive, but it pulls up a dos window momentarily. Is there anyway to stop this or minimize the window while it is executing?
>>
>>
>>declare long ShellExecute in "shell32.dll" long hwnd, string lpszOp, ;
>>string lpszFile, string lpszParams, ;
>>string lpszDir, long nShowCmd
>>declare long GetDesktopWindow in "win32api"
>>local hDCScreen
>>hDCScreen = GetDesktopWindow()
>>mcommand=" use * \\myserver\c$"
>>ShellExecute(hDCScreen, "open", "c:\winnt\system32\net.exe", mcommand, "c:\", 1 )
>
>Several. You can use the LaunchAppAndWait() function that I recently put up in the FAQ to use CreateProcess() to run the NET command completely hidden or minimized. You can use WNetAddConnection() (a Win32API call) to map the drive. You can use ShellExecuteEx (a more complex form of ShellExecute()) and populate the nShow member of the SHELLEXECUTEINFO structure with the correct code for the ShowWindow mode mode that you want (use the value I use in my CreateProcess() example in launchAppAndWait().) You can also use the ShellExecute() call and correctly populate the nShowCmd property (again, it uses the same SW_ values as CreateProcess() in the PROCESSINFO structure, or the nShow member of SHELLEXECUTEINFO).

The biggest advantages of CreateProcess is that (1) you can wait on the termination of the launched executable if desired, and (2) it returns a ProcessHandle that you can use to query its execution termination code, or use withTerminateProcess() if the app hangs. The biggest drawback is the complexity of the use of CreateProcess() correctly.

The easiest to implement is (4), since you already have ShellExecute() working. Changing the last value to either a 0 (hidden) or 2 (minimized) should do what you want. If there's any chance of a hang or wait on user response, I wouldn't use 0, since you can't change the launched executable's ShowWindow mode easily without a Process Handle, and it won't appear in a Win95/Win98 Task Manager process list if hidden.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform