how to assigning a Drive to a Share ?
-
how to assigning a Drive to a Share in c#? Currently, i try the API for make that but he don't run.... Could you help me ? public enum ResourceScope { RESOURCE_CONNECTED = 1, RESOURCE_GLOBALNET, RESOURCE_REMEMBERED, RESOURCE_RECENT, RESOURCE_CONTEXT }; public enum ResourceType { RESOURCETYPE_ANY, RESOURCETYPE_DISK, RESOURCETYPE_PRINT, RESOURCETYPE_RESERVED }; public enum ResourceUsage { RESOURCEUSAGE_CONNECTABLE = 0x00000001, RESOURCEUSAGE_CONTAINER = 0x00000002, RESOURCEUSAGE_NOLOCALDEVICE = 0x00000004, RESOURCEUSAGE_SIBLING = 0x00000008, RESOURCEUSAGE_ATTACHED = 0x00000010, RESOURCEUSAGE_ALL = (RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_ATTACHED), }; public enum ResourceDisplayType { RESOURCEDISPLAYTYPE_GENERIC, RESOURCEDISPLAYTYPE_DOMAIN, RESOURCEDISPLAYTYPE_SERVER, RESOURCEDISPLAYTYPE_SHARE, RESOURCEDISPLAYTYPE_FILE, RESOURCEDISPLAYTYPE_GROUP, RESOURCEDISPLAYTYPE_NETWORK, RESOURCEDISPLAYTYPE_ROOT, RESOURCEDISPLAYTYPE_SHAREADMIN, RESOURCEDISPLAYTYPE_DIRECTORY, RESOURCEDISPLAYTYPE_TREE, RESOURCEDISPLAYTYPE_NDSCONTAINER }; public class ServerEnum : IEnumerable { enum ErrorCodes { NO_ERROR = 0, ERROR_NO_MORE_ITEMS = 259 }; public class ServerEnum : IEnumerable { enum ErrorCodes { NO_ERROR = 0, ERROR_NO_MORE_ITEMS = 259 }; [StructLayout(LayoutKind.Sequential)] private class NETRESOURCE { public ResourceScope dwScope = 0; public ResourceType dwType = 0; public ResourceDisplayType dwDisplayType = 0; public ResourceUsage dwUsage = 0; public string lpLocalName = null; public string lpRemoteName = null; public string lpComment = null; public string lpProvider = null; }; [DllImport("Mpr.dll", EntryPoint="WNetAddConnection2", CallingConvention=CallingConvention.Winapi)] private static extern ErrorCodes WNetAddConnection2(NETRESOURCE lpNetResource,ref string lpPassword,ref string lpUsername, System.UInt32 dwFlags ); public void connectMapDrive(){ NETRESOURCE lpNetResource = new NETRESOURCE(); lpNetResource.dwType =ResourceType.RESOURCETYPE_ANY; lpNetResource.lpLocalName="O:"; lpNetResource.lpRemoteName= @"\\Bruxptest\Fichiers" ; lpNetResource.lpProvider = ""; string lpPassword ="PASSWORD**" ; string lpLocalName =@"bruxptest\ll2"; Erro
-
how to assigning a Drive to a Share in c#? Currently, i try the API for make that but he don't run.... Could you help me ? public enum ResourceScope { RESOURCE_CONNECTED = 1, RESOURCE_GLOBALNET, RESOURCE_REMEMBERED, RESOURCE_RECENT, RESOURCE_CONTEXT }; public enum ResourceType { RESOURCETYPE_ANY, RESOURCETYPE_DISK, RESOURCETYPE_PRINT, RESOURCETYPE_RESERVED }; public enum ResourceUsage { RESOURCEUSAGE_CONNECTABLE = 0x00000001, RESOURCEUSAGE_CONTAINER = 0x00000002, RESOURCEUSAGE_NOLOCALDEVICE = 0x00000004, RESOURCEUSAGE_SIBLING = 0x00000008, RESOURCEUSAGE_ATTACHED = 0x00000010, RESOURCEUSAGE_ALL = (RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_ATTACHED), }; public enum ResourceDisplayType { RESOURCEDISPLAYTYPE_GENERIC, RESOURCEDISPLAYTYPE_DOMAIN, RESOURCEDISPLAYTYPE_SERVER, RESOURCEDISPLAYTYPE_SHARE, RESOURCEDISPLAYTYPE_FILE, RESOURCEDISPLAYTYPE_GROUP, RESOURCEDISPLAYTYPE_NETWORK, RESOURCEDISPLAYTYPE_ROOT, RESOURCEDISPLAYTYPE_SHAREADMIN, RESOURCEDISPLAYTYPE_DIRECTORY, RESOURCEDISPLAYTYPE_TREE, RESOURCEDISPLAYTYPE_NDSCONTAINER }; public class ServerEnum : IEnumerable { enum ErrorCodes { NO_ERROR = 0, ERROR_NO_MORE_ITEMS = 259 }; public class ServerEnum : IEnumerable { enum ErrorCodes { NO_ERROR = 0, ERROR_NO_MORE_ITEMS = 259 }; [StructLayout(LayoutKind.Sequential)] private class NETRESOURCE { public ResourceScope dwScope = 0; public ResourceType dwType = 0; public ResourceDisplayType dwDisplayType = 0; public ResourceUsage dwUsage = 0; public string lpLocalName = null; public string lpRemoteName = null; public string lpComment = null; public string lpProvider = null; }; [DllImport("Mpr.dll", EntryPoint="WNetAddConnection2", CallingConvention=CallingConvention.Winapi)] private static extern ErrorCodes WNetAddConnection2(NETRESOURCE lpNetResource,ref string lpPassword,ref string lpUsername, System.UInt32 dwFlags ); public void connectMapDrive(){ NETRESOURCE lpNetResource = new NETRESOURCE(); lpNetResource.dwType =ResourceType.RESOURCETYPE_ANY; lpNetResource.lpLocalName="O:"; lpNetResource.lpRemoteName= @"\\Bruxptest\Fichiers" ; lpNetResource.lpProvider = ""; string lpPassword ="PASSWORD**" ; string lpLocalName =@"bruxptest\ll2"; Erro
First, you didn't describe any errors or what exactly the problem was. It's very hard to help you when you don't mention specific problems. Second, why not make this easier:
string drive = "X"; // Or whatever
string share = @"\\machine\share"; // Or whatever
Process.Start("net.exe", string.Format("use {0}: {1}", drive, share));You could easily add switches for a username and password, too. Type "net use /?" in the command prompt for more information. If you'd rather do this programmatically, then please be more specific about the nature of your problem.
Microsoft MVP, Visual C# My Articles
-
First, you didn't describe any errors or what exactly the problem was. It's very hard to help you when you don't mention specific problems. Second, why not make this easier:
string drive = "X"; // Or whatever
string share = @"\\machine\share"; // Or whatever
Process.Start("net.exe", string.Format("use {0}: {1}", drive, share));You could easily add switches for a username and password, too. Type "net use /?" in the command prompt for more information. If you'd rather do this programmatically, then please be more specific about the nature of your problem.
Microsoft MVP, Visual C# My Articles
sorry, I would like to make a windows service which able to check and map the shared drive automatically. When i launch my api for that, I receive a error message 2202: ERROR_INVALID_WINDOW_STYLE the equivalence in c++ is : #include #include #include void main() { NETRESOURCE nr; DWORD res; TCHAR szUserName[32] = "MyUserName", szPassword[32] = "MyPassword", szLocalName[32] = "Q:", szRemoteName[MAX_PATH] = "\\\\products2\\relsys"; // // Assign values to the NETRESOURCE structure. // nr.dwType = RESOURCETYPE_ANY; nr.lpLocalName = szLocalName; nr.lpRemoteName = szRemoteName; nr.lpProvider = NULL; // // Call the WNetAddConnection2 function to assign // a drive letter to the share. // res = WNetAddConnection2(&nr, szPassword, szUserName, FALSE); // // If the call succeeds, inform the user; otherwise, // print the error. // if(res == NO_ERROR) printf("Connection added \n", szRemoteName); else printf("Error: %ld\n", res); return; } and it is work? -=zoltx=-
-
sorry, I would like to make a windows service which able to check and map the shared drive automatically. When i launch my api for that, I receive a error message 2202: ERROR_INVALID_WINDOW_STYLE the equivalence in c++ is : #include #include #include void main() { NETRESOURCE nr; DWORD res; TCHAR szUserName[32] = "MyUserName", szPassword[32] = "MyPassword", szLocalName[32] = "Q:", szRemoteName[MAX_PATH] = "\\\\products2\\relsys"; // // Assign values to the NETRESOURCE structure. // nr.dwType = RESOURCETYPE_ANY; nr.lpLocalName = szLocalName; nr.lpRemoteName = szRemoteName; nr.lpProvider = NULL; // // Call the WNetAddConnection2 function to assign // a drive letter to the share. // res = WNetAddConnection2(&nr, szPassword, szUserName, FALSE); // // If the call succeeds, inform the user; otherwise, // print the error. // if(res == NO_ERROR) printf("Connection added \n", szRemoteName); else printf("Error: %ld\n", res); return; } and it is work? -=zoltx=-
Are you running the app as the LOCAL SYSTEM account or as a user? Also, you have to tag the service as able to interact with the desktop. RageInTheMachine9532
-
Are you running the app as the LOCAL SYSTEM account or as a user? Also, you have to tag the service as able to interact with the desktop. RageInTheMachine9532