Jump to content

Recommended Posts

Posted

Hello All,

I am developing an application that will run continuously in the background on a users workstation. This application will automatically transfer files from the local machine to a remote server and vise versa. It checks for the files on a timed interval. I have two problems with this application that I am having trouble figuring out:

The first problem is that the cmd.exe shell pops up on the screen every time it maps the drive. The application needs to be completely 'invisible' to the user. I cannot have something popping up every several minutes while they are trying to work. :sneaky:

The second issue is that I do not want to let a continuous connection to the remote server so I have mapped a network drive to the remote server using process.start. I have provided administrative credentials when creating the drive. Local users do not have permission to connect to the remote server. Also, I only want to create the drive when necessary, and then close it when the current process is finished with it.

The drive mapping shows in My Computer when I check for it. However, when the code tries to access the drive to transfer the files, I get an error and the program shuts down. :angry:

The error is: system.unauthorizedaccess, eventtype: clr20r3.

I am assuming this has something to do with the user credentials, so I tried creating the mapped drive using the same command lines in my code using the command prompt. I was able to successfully create the mapped drive and access it under the local user account :wacko:

Any ideas/help would greatly be appreciated.

This is the section of code that I am using to create the drive:

Try

srvConn = New System.Diagnostics.Process

srvConn.StartInfo.UseShellExecute = False

srvConn.StartInfo.RedirectStandardError = True

srvConn.StartInfo.RedirectStandardOutput = True

srvConn.StartInfo.FileName = ("net.exe")

srvConn.StartInfo.Arguments = "use z: \\server\share" & " " & My.Settings.rbsSrvPwd & "/user:" & My.Settings.rbsSrvUsr

srvConn.Start()

srvConn.WaitForExit()

Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException

Microsoft.VisualBasic.FileIO.FileSystem.WriteAllText(My.Settings.logPoll, "Error: " & ex.Message & " occurred in rbsSrvConnection:rbsConnOpen" & vbCrLf, True)

End Try


Posted

After some experimentation, I was able to get it to work. :thumbup I am posting my solution in the event that it will help someone else. There were two things I was doing wrong:

1. I did not provide a redirect for the input. Seems you need to redirect error, input, and output even if you are not using the data.

2. I was using WaitForExit in the wrong context.

Here is the code that works:

info.StartInfo.FileName = ("net.exe")

info.StartInfo.UseShellExecute = False

info.StartInfo.RedirectStandardInput = True

info.StartInfo.RedirectStandardError = True

info.StartInfo.RedirectStandardOutput = True

info.StartInfo.CreateNoWindow = True

info.StartInfo.WindowStyle = ProcessWindowStyle.Hidden

info.StartInfo.Arguments = "use z: \\server\share " & My.Settings.rbsSrvPwd & " /user:" & My.Settings.rbsSrvUsr

Process.Start(info.StartInfo)

If anyone sees any flaws please let me know.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...