2011-07-04 4 views
0

私は以下のコードを試してみましたが、うまくいきましたが、私は今、パスワードを渡して、rdp connection.everytimeを開いたときにポップアップメッセージを表示しないようにします。sw.WriteLine("password 51:b:" + password); エラー「エラーがファイルc:\ temp.rdpをダウンロードできません」というメッセージが表示されるsmtscフォームC#コード

public static void RdcTest(String server,String UserName,String password) 
    { 

     string filename = @"c:\temp.rdp"; 

     if (!File.Exists(filename)) 
     { 

      using (FileStream fs = File.Create(filename)) 

      using (StreamWriter sw = new StreamWriter(fs)) 
      { 

       sw.WriteLine("screen mode id:i:2"); 
       sw.WriteLine("desktopwidth:i:1440"); 
       sw.WriteLine("desktopheight:i:900"); 
       sw.WriteLine("session bpp:i:32"); 
       sw.WriteLine("winposstr:s:0,1,4,12,1440,864"); 
       sw.WriteLine("compression:i:1"); 
       sw.WriteLine("keyboardhook:i:2"); 
       sw.WriteLine("displayconnectionbar:i:1"); 
       sw.WriteLine("disable wallpaper:i:1"); 
       sw.WriteLine("disable full window drag:i:1"); 
       sw.WriteLine("allow desktop composition:i:0"); 
       sw.WriteLine("allow font smoothing:i:0"); 
       sw.WriteLine("disable menu anims:i:1"); 
       sw.WriteLine("disable themes:i:0"); 
       sw.WriteLine("disable cursor setting:i:0"); 
       sw.WriteLine("bitmapcachepersistenable:i:1"); 
       sw.WriteLine("full address:s:" + server); 
       sw.WriteLine("username:s:" + UserName); 
       //sw.WriteLine("password 51:b:" + password); 
       sw.WriteLine("audiomode:i:0"); 
       sw.WriteLine("redirectprinters:i:1"); 
       sw.WriteLine("redirectcomports:i:0"); 
       sw.WriteLine("redirectsmartcards:i:1"); 
       sw.WriteLine("redirectclipboard:i:1"); 
       sw.WriteLine("redirectposdevices:i:0"); 
       sw.WriteLine("autoreconnection enabled:i:1"); 
       sw.WriteLine("authentication level:i:0"); 
       sw.WriteLine("prompt for credentials:i:0"); 
       sw.WriteLine("negotiate security layer:i:1"); 
       sw.WriteLine("remoteapplicationmode:i:0"); 

       //sw.WriteLine("domain:s:" + domain); 

      } 

      Process rdcProcess = new Process(); 

      string strExE = Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\mstsc.exe"); 

      rdcProcess.StartInfo.FileName = strExE; 

      rdcProcess.StartInfo.Arguments = filename; 

      rdcProcess.Start(); 

     } 

    } 

答えて

0

問題はおそらくあなたのコードdosentに "c:\ temp.rdp"を作成する権限があることでしょう。あなたのコードによってファイルシステム上にファイルが作成されていることを確認できますか?

+0

ファイルが正常に作成された –

+0

問題は行内にあります。sw.WriteLine( "password 51:b:" + password);私はすべてのものがうまく動作するとコメントしますが、有効にするとエラーメッセージが表示されます –

関連する問題