简体   繁体   中英

Execute remote batch file from within a C# forms application

I am working on a VPN dialer that will execute a login script when the connection is successfull using the following method.

        Process p = new Process();
        try
        {
            p.StartInfo.UseShellExecute = true;
            p.StartInfo.FileName = @"\\serverName\NETLOGON\Script Test.cmd";
            p.Start();
            p.WaitForExit();
            }
        }

        catch (Exception ex)
        {

        }

The batch file execute properly according to the logging methods in the batch file, but the drives are not acctualy mapped for the user to use. Other batch files tested (local & remote) have the same result.

I am assuming this has something to do with the application domain or UAC. The finished application will run on Viata/7 and is being tested on Windows 7.

Any help here would be greatly appreciated.

Regards Bert

Mapped Drives are stored in a users profile. Which typically gets loaded when the person logs in. The most common way to get access to profile associated resources is to impersonate the user.

There is a relationally poor (PInvoke) example of how to do this here: http://support.microsoft.com/kb/306158#4

But generally using mapped drives from a script is asking for trouble. IMHO :)

Hope that helps,

Jan

You can check if there is any exception happened. I see catch(exception ex) swallows you exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM