473,394 Members | 1,706 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.

Network Share+File.Copy+Logon Failure

PRM
Hi
I am sharing a network drive, by using the following code (C# Code using ASP.net
/************************************************** ********************************
public void ShareMap(string machineName, string username, string password, string ShareName

System.Management.ManagementScope sc = null

ConnectionOptions co = null

tr

co = new ConnectionOptions()

co.Impersonation = ImpersonationLevel.Impersonate

//co.Impersonation = ImpersonationLevel.Delegate

co.EnablePrivileges = true

if (machineName.ToUpper() == Environment.MachineName.ToUpper()

sc = new ManagementScope(@"\ROOT\CIMV2", co)

els

co.Username = username

co.Password = password

sc = new ManagementScope(@"\\" + machineName + @"\ROOT\CIMV2", co)

sc.Connect()

ManagementBaseObject inParams = null
ManagementClass classObj = new ManagementClass(sc, new ManagementPath("Win32_Share"), null)
inParams = classObj.GetMethodParameters("Create")
inParams["Access"] = null; // default Security descriptor use
inParams["Description"] = "Shared for Admin Purposes"
inParams["MaximumAllowed"] = 10
inParams["Name"] = ShareName
inParams["Password"] = password
inParams["Path"] = @"c:\"
inParams["Type"] = 0; // Disk drive 0, print queue
ManagementBaseObject outParams = classObj.InvokeMethod("Create", inParams, null)
catch (Exception ex

throw ex

finall



/************************************************** ************************

and then trying to copy using

string sSource = @"c:\temp\test.exe"
string sExepath = @"\\"+sRemoteMachineName+@"\C$\test.exe"
// Copy the file
File.Copy(sSource, sExepath,true)

This is when I get th
System.Io.Exception: Logon Failure: unknown user name or bad password, Error. I dont get this error when I am running thee application as a C# Console application. But when I run the same code in an ASp.net web page. I have these problems

Any feedback would be appreciated

I need to be able to dynamically share drives on different machines and copy file

Regards
PR
Nov 16 '05 #1
0 6141

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

Similar topics

8
by: Michelle | last post by:
Hello! I have an ASP.NET application (1.1 framework) that needs to be able to read/write files on a network share. The access to this file share will be fairly restricted, so I need to...
23
by: Lamberti Fabrizio | last post by:
Hi all, I've to access to a network file from an asp pages. I've red a lot of things on old posts and on Microsoft article but I can't still solve my problem. I've got two server inside the...
36
by: Thomas | last post by:
after spending countless hours trying, i give up and hope to get some help in here. on server1 i got the web myweb.com with my test.asp. in the test.asp, i'm trying to read a file from an UNC...
4
by: Jason Shohet | last post by:
A user runs a .NET application that authenticates them against active directory (they're coming in over VPN so they don't log on to the network normally). Once they log in, I want to take their...
8
by: Lam | last post by:
HI anyone knows how can I open a mapped network file in C#? I try string file = @"T:\file.txt"; it shows me the error: "Could not find a part of the path" but if I copy the file to my C dirve,...
2
by: pj_servadmin | last post by:
Server Error in '/<applicationName>' Application -------------------------------------------------------------------------------- Parser Error Description: An error occurred during the parsing of...
1
by: Daniel | last post by:
How to access a network file path \\foo\bar.txt from an .aspx and from a custom IHttpHandler? How to specify which account that aspx application should use when doing file IO from network paths?...
20
by: =?Utf-8?B?QnJpYW4gTmljaG9sc29u?= | last post by:
Hello, I'm trying to create an admin page that can run miscellaneous scripts for our IT department. Currently, I'm trying to create a script that can map a network drive for a user (e.g. a form...
5
by: =?Utf-8?B?QWRyaWFuTW9ycmlz?= | last post by:
Hello! I'm trying to copy a file from another computer on the network that I do not have permission with my current logon details to access. If I open the folder using the Windows file manager...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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,...

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.