public void CreateDir(string DriverPath) { IntPtr token = IntPtr.Zero; WindowsImpersonationContext impersonatedUser = null; Hashtable Fod_Files = new Hashtable(); try { // Create a token for DomainName\UserName //Call LogonUser function to obtain an access token // for the specified user client_Uname = "a1093557"; // client_IPAddress = "india.airtel.itm"; client_pwd = "sairam@9"; DomainName = "india.airtel.itm"; bool result = LogonUser(client_Uname, DomainName, client_pwd, LogonSessionType.NewCredentials, LogonProvider.Default, out token); if (result) { //create a new window identity from the window access token WindowsIdentity id = new WindowsIdentity(token); // Begin impersonation impersonatedUser = id.Impersonate(); Drv_FolderPath = @"C:\PrntDriver1"; DriverPath = @"\\10.14.65.85\C$\hp"; if (Directory.Exists(Drv_FolderPath)) { //DeleteDir(); } // Drv_FolderPath = @"\\" + client_IPAddress + @"\C$\PrntDriver"; System.IO.Directory.CreateDirectory(Drv_FolderPath); Fod_Files = Chk_Files(DriverPath); string[] FileName = null; string[] Drv_Fold = null; Drv_Fold = DriverPath.Split('\\'); int i = Drv_Fold.Length; //loop on hashtable which contains all the file with their path foreach (string f in Fod_Files.Values) { FileName = f.Split('\\'); string Dest_Path = Drv_FolderPath + @"\" + FileName[i]; if (!File.Exists(Dest_Path)) { //it will copy files on client machine System.IO.File.Copy(f, Dest_Path); } } // utl.putLogData(DateTime.Now.ToString() + " Driver setup copied successfully "); } else { } } catch (Exception ex) { } finally { // Stop impersonation and revert to the process identity if (impersonatedUser != null) impersonatedUser.Undo(); //// Free the token if (token != IntPtr.Zero) CloseHandle(token); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)