Jump to content
Xtreme .Net Talk

sizer

Avatar/Signature
  • Posts

    123
  • Joined

  • Last visited

Everything posted by sizer

  1. sizer

    Map drive

    found a problem I found the problem :eek: :eek: :eek: ... ... //WRONG WNetAddConnection2( ref nr, strUsername, strPassword, 0); //CORRECT WNetAddConnection2( ref nr, strPassword, strUsername, 0); LoL When you test with same username and password (like me) than the first one is correct too :)))))) ... ... Now works perfect :). Regards,
  2. sizer

    Map drive

    Hi, I'm trying to map network drive with this code: [system.Runtime.InteropServices.DllImport("mpr.dll", EntryPoint="WNetAddConnection2A",SetLastError=true)] public static extern int WNetAddConnection2(ref NETRESOURCE lpNetResource, string lpPassword, string lpUserName, int dwFlags); [system.Runtime.InteropServices.DllImport("mpr", EntryPoint="WNetCancelConnection2A")] public static extern int WNetCancelConnection2(string lpName, int dwFlags, int fForce); [structLayout(LayoutKind.Sequential)] public struct NETRESOURCE { public int dwScope; public int dwType; public int dwDisplayType; public int dwUsage; public string lpLocalName; public string lpRemoteName; public string lpComment; public string lpProvider; } public const int ForceDisconnect = 1; public const long RESOURCETYPE_DISK = 1; public const Int32 CONNECT_UPDATE_PROFILE = 0x1; public bool MapDrive(string DriveLetter, string UNCPath,string username,string password) { NETRESOURCE nr; string strUsername; string strPassword; nr = new NETRESOURCE(); nr.lpRemoteName = @"\\127.0.0.1\share";//UNCPath.ToString(); nr.lpLocalName ="Z:"; //DriveLetter.ToString() + ":"; strUsername ="SomeUser"; //username; strPassword ="SomePass"; //password; nr.dwType = (int)RESOURCETYPE_DISK; int result; result = WNetAddConnection2( ref nr, strUsername, strPassword, 0); if (result == 0) { return true; } else { throw new Win32Exception(result); //return false; } } Everthing works fine (for Workgroup), but on domain won't work, even if i put for username=DOMAIN\user (user is domain admin, full permissions are granted). Following exception is thrown: Logon failure: unknown user name or bad password Any suggestions? Regards,
  3. this happens because you didnt specify a table that is inside dataset the correct code in your example is: DG1.DataSource = ds.Tables(0) ''or DG1.DataSource = ds.Tables("Table") :)
  4. you can implement three functions with same name and different args ( AKA polymorfism ) , it is better solution that looping thru the array ... Example ... ... public Function Hello() MessageBox.Show("Hello Mister") End Function public Function Hello(strFirstName as String) MessageBox.Show("Hello Mister " + strFirstName) End Function public Function Hello(strFirstName As String, strLastName As String) MessageBox.Show("Hello Mister " + strFirstName + " " + strLastName) End Function ... ... :D
  5. actually there is framework for linux :):) check this site http://www.mono-project.com/about/index.html
  6. post some code where you implemented file deletation
  7. i) you need to decide what crypto system do you need ( RSA,DES , TripleDes ...) , some of this are asymmetric crypto systems and other are symetric. ii) asymmetric crypto systems have to different keys ( public and private), public key will be used for crypt some txt ( document , picture ....), and private key is used for decrypt, while symetric crypto systems have one key for both directions iii) framework includes most of these systems ( System.Security.Cryptography ), so you dont need to worry about very large prime numbers which is base of every crypo system , implementation of oprerations for these numbers ( i hated that part :) ) , and other stuff like that! iv) RSA example using System; using System.Security.Cryptography; using System.Text; class RSACSPSample { static void Main() { try { //Create a UnicodeEncoder to convert between byte array and string. UnicodeEncoding ByteConverter = new UnicodeEncoding(); //Create byte arrays to hold original, encrypted, and decrypted data. byte[] dataToEncrypt = ByteConverter.GetBytes("Data to Encrypt"); byte[] encryptedData; byte[] decryptedData; //Create a new instance of RSACryptoServiceProvider to generate //public and private key data. RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(); //Pass the data to ENCRYPT, the public key information //(using RSACryptoServiceProvider.ExportParameters(false), //and a boolean flag specifying no OAEP padding. encryptedData = RSAEncrypt(dataToEncrypt,RSA.ExportParameters(false), false); //Pass the data to DECRYPT, the private key information //(using RSACryptoServiceProvider.ExportParameters(true), //and a boolean flag specifying no OAEP padding. decryptedData = RSADecrypt(encryptedData,RSA.ExportParameters(true), false); //Display the decrypted plaintext to the console. Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData)); } catch(ArgumentNullException) { //Catch this exception in case the encryption did //not succeed. Console.WriteLine("Encryption failed."); } } static public byte[] RSAEncrypt(byte[] DataToEncrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding) { try { //Create a new instance of RSACryptoServiceProvider. RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(); //Import the RSA Key information. This only needs //toinclude the public key information. RSA.ImportParameters(RSAKeyInfo); //Encrypt the passed byte array and specify OAEP padding. //OAEP padding is only available on Microsoft Windows XP or //later. return RSA.Encrypt(DataToEncrypt, DoOAEPPadding); } //Catch and display a CryptographicException //to the console. catch(CryptographicException e) { Console.WriteLine(e.Message); return null; } } static public byte[] RSADecrypt(byte[] DataToDecrypt, RSAParameters RSAKeyInfo,bool DoOAEPPadding) { try { //Create a new instance of RSACryptoServiceProvider. RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(); //Import the RSA Key information. This needs //to include the private key information. RSA.ImportParameters(RSAKeyInfo); //Decrypt the passed byte array and specify OAEP padding. //OAEP padding is only available on Microsoft Windows XP or //later. return RSA.Decrypt(DataToDecrypt, DoOAEPPadding); } //Catch and display a CryptographicException //to the console. catch(CryptographicException e) { Console.WriteLine(e.ToString()); return null; } } } this example outputs result to Conslole see link for more info http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemsecuritycryptographyrsacryptoserviceproviderclasstopic.asp :D
  8. Problem "solved" ok, i found the problem ,,code above works fine , but if you try to ask user with MessageBox "Are you sure" for example then code above doesn't work,, so i'm traping WM_ENDSESSION and immidetly after that i'm sending WM_CANCELMODE. If user click "Yes" for example :) i'm calling other class that shutdown the computer... :cool: :D
  9. no, it is backup tool!
  10. i need to know when/if that happens , because i want to close my application properly!
  11. hi, i have a problem with stopping windows to shutdown , i founded some code private int WM_QUERYENDSESSION = 0x11; private int WM_CANCELMODE = 0x1F; protected override void WndProc(ref Message m) { if (m.Msg == WM_QUERYENDSESSION) { Message x = new Message(); x.Msg = WM_CANCELMODE; base.WndProc(x); } else { base.WndProc(m); } } but this code doesn't work ,,, windows is still shuting down ( logging off or restart )! Any ideas? tx...
  12. hi! I have a very large collection of MS Word Documents , and i have to extract all images from this Docs! Well i have no clue how to start , can anyone post some short example,some explanation or link where i can find something about that! Thanks in advice!
  13. heh, i figured out , tnx for your replay!! :D
  14. tnx.... I want to set proxy server on my Internet Connection,but i have a problem with reading binary value from my Internet Connection! Do you know anything about that ?
  15. hi! Can anyone explain me how to put binary value in Registry using C#?
  16. try with this code: ds.Tables["myTable"].Columns["myColumn"].ColumnMapping = MappingType.Hidden; or ds.Tables("myTable").Columns("myColumn").ColumnMapping = MappingType.Hidden :D
  17. code for c# is: protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { switch (keyData) { case Keys.Control | Keys.M: MessageBox.Show ("CTRL+M"); break; case Keys.Control | Keys.D1: MessageBox.Show ("CTRL+1"); break; //and so on } return base.ProcessCmdKey(ref msg,keyData); } for vb : ['vb] code ['/vb] for c# : ['cs] code ['/cs] without quotes! :D
  18. try with this: Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean If keyData = (Keys.Control Or Keys.D1) Then MessageBox.Show("You pressed CTRL+1") Return (True) End Function :D
  19. before sqlDataAdapter->Update(ds, "Authors"); command put this->BindingContext(myDSet, MyDataTable.TableName())->EndCurrentEdit()
  20. sizer

    Arrays?

    try this : For x = 0 To MyArray.GetUpperBound() - 1 'some stuff here Next :D
  21. did you try to install patch crnet_keycodefix.zip from http://support.crystaldecisions.com/downloads
  22. look at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchdistributingapplicationscreatedwithvisualbasicnet.asp hope this helps :D
  23. Create Setup and install your App, instead manualy coping file on target machine , or you can register DLL with: Start-->Run-->regsvr32 path\your.dll :D
×
×
  • Create New...