Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-07-2008, 02:51 PM   PM User | #1
jlimited
New Coder

 
Join Date: Sep 2006
Posts: 32
Thanks: 5
Thanked 0 Times in 0 Posts
jlimited is an unknown quantity at this point
C# Pulling Process ID

Hello,

I have a log on script to launch an application. Mostly it maps network drives on the local computer that are hard coded into the application (IE The application was not designed for a network based install).

I want to build a *.exe that reads from a SQL Database for permissions for a given user. (IE: The application development team needs to have the testing environment mapped).

Currently, I have a *.bat file searches a network folder using the IF EXISIT function. If there is a file in that folder named by the user's login ID, then they extra drive is mapped. If there is not one, then the extra drive is not mapped.

In the batch script I call the NET USE function.
1. First I delete the old drive mapping.
2. Then I map that drive letter to the correct location.

I have the C# code working. My problem is that is runs the code to quickly. The old drive does not completely unmap prior to the new mapping command being executed causing Windows Explorer to do weird things (It shows that it is still mapped to the old location, or when the other command is completed it doesn’t show at all, until I call it in the address bar).

This code using the System.Diagnostics

Code:
//Delete Old Drive Mappings
Process.Start(@"C:/WINDOWS/System32/net.exe", @"use "+driveLetter+" /delete");

//Map Drives
Process.Start(@"C:/WINDOWS/System32/net.exe", @"use "+driveLetter+" "+networkLocation);
I want to place a dynamic wait in between these commands. Obtain Process ID for the process that just started (Delete Old Drive Mappings). Wait until process is shutdown. Execute map command.

I am not sure how to obtain the process ID for the process that just started.

Thanks
jlimited
jlimited is offline   Reply With Quote
Old 07-07-2008, 03:35 PM   PM User | #2
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
Hmm. I ran your code and everything seemed fine when I tried to access the mapped drives. At any rate, look into Process.Id and System.Threading.Thread.Sleep:
Code:
Process p = Process.Start(@"C:/WINDOWS/System32/net.exe", @"use "+driveLetter+" /delete");
// p.Id should have the generated id
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:39 PM.


Advertisement
Log in to turn off these ads.