473,763 Members | 1,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error when trying to programmaticall y 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.unauthor izedaccess, 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.Diagnost ics.Process
srvConn.StartIn fo.UseShellExec ute = False
srvConn.StartIn fo.RedirectStan dardError = True
srvConn.StartIn fo.RedirectStan dardOutput = True
srvConn.StartIn fo.FileName = ("net.exe")
srvConn.StartIn fo.Arguments = "use z: \\server\share" & " " &
My.Settings.rbs SrvPwd & "/user:" & My.Settings.rbs SrvUsr
srvConn.Start()
srvConn.WaitFor Exit()

Catch ex As Microsoft.Visua lBasic.FileIO.M alformedLineExc eption
Microsoft.Visua lBasic.FileIO.F ileSystem.Write AllText(My.Sett ings.logPoll,
"Error: " & ex.Message & " occurred in rbsSrvConnectio n:rbsConnOpen" &
vbCrLf, True)
End Try

Jul 20 '06 #1
1 2519
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. RedirectStandar dInput = True
info.StartInfo. RedirectStandar dError = True
info.StartInfo. RedirectStandar dOutput = True
info.StartInfo. CreateNoWindow = True
info.StartInfo. WindowStyle = ProcessWindowSt yle.Hidden
info.StartInfo. Arguments = "use z: \\server\share " &
My.Settings.rbs SrvPwd & " /user:" & My.Settings.rbs SrvUsr

Process.Start(i nfo.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.unauthor izedaccess, 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.Diagnost ics.Process
srvConn.StartIn fo.UseShellExec ute = False
srvConn.StartIn fo.RedirectStan dardError = True
srvConn.StartIn fo.RedirectStan dardOutput = True
srvConn.StartIn fo.FileName = ("net.exe")
srvConn.StartIn fo.Arguments = "use z: \\server\share" & " " &
My.Settings.rbs SrvPwd & "/user:" & My.Settings.rbs SrvUsr
srvConn.Start()
srvConn.WaitFor Exit()

Catch ex As Microsoft.Visua lBasic.FileIO.M alformedLineExc eption
Microsoft.Visua lBasic.FileIO.F ileSystem.Write AllText(My.Sett ings.logPoll,
"Error: " & ex.Message & " occurred in rbsSrvConnectio n: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
1377
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 error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x444 Thread 0xfe4 DBC 0x5200024 Jet'.
1
2141
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 except form files. Their code opens fine but trying to open them in the form designer I get (for instance) "The item 'MainForm.vb' does not exist in the project directory. It
8
6683
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 applications work fine on IIS 4. Here is the scenario: - Mapped Drives on server to anotheer network Drive (I.E. - Q:\) - IIS uses different Domain accounts for anonymous access (based on the application). - These domain accounts have all of...
6
3669
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 part of the path "D:\". My site is hosted on a public ISP that for obvious security reasons does not allow my read access above my wwwroot folder which seems to be a problem when trying to create directories... Is there any way to solve this?
9
3215
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 questions are below... "David Good" wrote: > We have a network running both Win2k and Win2k3 webservers and our web sites > reside on a UNC network share that happens to be a Network Appliance NAS.
2
1068
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 a mapped drive, installing to a mapped drive is not supported." Yet non of my components are set to go to a mapped drive. They are all set to go to default c:\Program Files. Help appreciated. Thanks, Frank
8
55680
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 everything I've tried, I cannot get MySQL to start as a Windows service. However, I AM able to get it started via the mysqld-nt --console command. Here is my (funky) setup:
2
9912
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 network drive, then moves a specified file to the remote server. I've imported the SDK API "WNetAddConnection2A" to map the network drive.
9
7125
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 database engine cannot open the file '(unknown)'. It is already opened exclusively by another user, or you need permission to view its data., SQL state S1000 in SQLConnect in ... The file is NOT already opened exclusively (or in any other manner)...
0
9563
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10145
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9822
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.