473,394 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

error when trying to programmatically access a mapped drive

Hello All,

I am developing an application in visual basic 2005 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.

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.

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

Any ideas/help would greatly be appreciated.

This is the section of code that I am calling when I want 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.MalformedLineExceptio n
Microsoft.VisualBasic.FileIO.FileSystem.WriteAllTe xt(My.Settings.logPoll,
"Error: " & ex.Message & " occurred in rbsSrvConnection:rbsConnOpen" &
vbCrLf, True)
End Try

Jul 20 '06 #1
1 2483
After some experimentation, I was able to get it to work. 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.
"maz01" wrote:
Hello All,

I am developing an application in visual basic 2005 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.

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.

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

Any ideas/help would greatly be appreciated.

This is the section of code that I am calling when I want 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.MalformedLineExceptio n
Microsoft.VisualBasic.FileIO.FileSystem.WriteAllTe xt(My.Settings.logPoll,
"Error: " & ex.Message & " occurred in rbsSrvConnection:rbsConnOpen" &
vbCrLf, True)
End Try
Jul 27 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: M P | last post by:
What does this mean? I am accessing an ASP page that queries Access Database thru fileDSN. I'm using IIS 5.0 Win2K SP4 Microsoft OLE DB Provider for ODBC Drivers error '80004005' General...
1
by: MC | last post by:
Hi all, I've read the various posts concerning file access on mapped drives--I think problem is different: The problem: Open a VB Winforms project from a mapped drive and all files open fine...
8
by: Matt | last post by:
I am migrating from NT 4.0 (IIS 4) to 2003 Server (IIS 6). Our Intranet has numerous applications that utilize the FileSystemObject (FSO) and each one is returning a "Path not found." error. These...
6
by: Eran Kampf | last post by:
I am trying to dynamically create directories in my ASP.NET application (I am using Server.MapPath("/")+"test" as the folder) and I am getting a DirectoryNotFoundException saying "Could not find a...
9
by: Tim D | last post by:
Hi, I originally posted this as a reply to a rather old thread in dotnet.framework.general and didn't get any response. I thought it might be more relevant here; anyone got any ideas? My...
2
by: Frank Bishop | last post by:
I am getting a mapped drive error when trying to install VS.net 2003 on a Windows 2003 server. After I select which components to install, I get: "At least one component has an install path set to...
8
by: Kevin D. | last post by:
Please note, I already posted this on the MySQL official forum, but received no response. I thought I'd try again in another location. My apologies to anyone reading this twice... Despite...
2
by: Tomas Vera | last post by:
Hello All, I have a web application that is required to copy a file from the WebServer to a remote web server (staging server to production server). I've created an application that maps the...
9
by: Martin | last post by:
Using ODBC in a PHP script, I'm trying to read an MS Access MDB file that resides on another computer on my LAN. I'm getting the error: Warning: odbc_connect() : SQL error: The Microsoft Jet...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.