I want to create a remote desktop connection with C#. I found this question Run mstsc.exe with specified username and password.
At the moment I can create a new connection with username and password, but I want to change the path where the .rdp file will be saved.
Maybe you have an idea how I can change the save path.
Better that setting the default path, you can create the rdp file itself and save it in the default path.
the rdp file should contain the below content.
"full address:s:" + IP
"username:s:" + User
"domain:s:" + Domain
"password 51:b:" + Pass
"port:i:" + Port
"screen mode id:i:1"
"desktopwidth:i:800"
"desktopheight:i:600"
"session bpp:i:32"
"auto connect:i:1"
"autoreconnection enabled:i:1"
"compression:i:1"
"keyboardhook:i:2"
"audiomode:i:2"
"redirectdrives:i:1"
"redirectprinters:i:1"
"redirectcomports:i:0"
"redirectsmartcards:i:0"
"displayconnectionbar:i:1"
"alternate shell:s:"
"shell working directory:s:"
"disable wallpaper:i:1"
"disable full window drag:i:1"
"disable menu anims:i:1"
"disable themes:i:1"
"bitmapcachepersistenable:i:1";
Related
I've created a function that works perfectly within the same domain.
It can take a name like "Win7-Alpha" and return "Win7-Alpha.Alpha.ca" when being used on the "Alpha.ca" Domain.
public static string TryGetServerFQDN(string ServerName)
{
string ServerFQDN = ServerName;
if (!string.IsNullOrEmpty(ServerName))
{
IPHostEntry serverIPEntry = null;
try
{
serverIPEntry = Dns.GetHostEntry(ServerName);
}
catch
{
}
if (serverIPEntry != null && !string.IsNullOrEmpty(serverIPEntry.HostName))
{
ServerFQDN = serverIPEntry.HostName;
}
}
return ServerFQDN;
}
However, if I try the very same thing on the "Beta.ca" Domain, it only returns "Win7-Alpha". It is able to resolve the IPv4 Address if it is passed instead, but again, it only returns "Win7-Alpha"....
I don't want just "Win7-Alpha", I want the FQDN!
On Beta.ca DNS I can see the FQDN that I want so why won't it give it to me?
It appears that Microsoft has done some very questionable coding practices. From what I can tell, Windows won't give you the FQDN name from another domain, but you can set up a DNS Suffix List that will force querying a name with Domain suffixes. This appears to force Windows to search for an entry that matches the FQDN (even though it can do this with just the hostname). The difference is when it return the IP Address and the name it used, the name it used was the FQDN it created from the List you specified.
I have verified that once I had the machine with the list, I was able to use my function and it would resolve the HostName from another domain to the correct FQDN.
On the machine itself
Click Start
Search for "Network and Sharing Center"
Click "Change adapter settings"
For each Adapter, Right Click it and select Properties
Click either Internet Protocol Version 6 (TCP/IPv6) or Internet Protocol Version 4 (TCP/IPv4)
Click "Properties" button
Click "Advanced..." button
Click DNS Tab
Select Option "Append these DNS suffixes (in order)"
Click "Add..." and add the domain you are on first
Repeat click "Add..." and add each domain you might need the FQDN from.
Again, ensure the top of the list is the domain this machine is on
Click OK on the Advanced TCP/IP Settings Window
Click OK on the Internet Protocol Properties Window
Click "Close" or "OK" on the Adapter Properties Window
Try pinging a computer by name on a different domain, you should see the FQDN returned.
You can also IPv4 ping via "ping -4 COMPUTERNAME"
If it doesn't appear working:
Open cmd.exe as Admin
ipconfig /flushdns
ipconfig /registerdns
Or Using Group Policy
Run Group Policy Management with sufficient Domain/Forest
Administrator Credentials
Select what Policy you want to alter. In this example, Default Domain Policy
Right Click and choose Edit
Navigate down to [Computer Configuration > Policies > Administrative Templates > Network > DNS Client]
Open "DNS Suffix Search List"
Select "Enable"
In the DNS Suffixes textbox, type your Comma separated DNS Suffixes. Ex. We are on Beta.ca domain, so we type Beta.ca,Alpha.ca
Click OK or Apply then close the Windows
If you need to policy to apply to a machine ASAP, on the machine you can open cmd.exe and type gpupdate /force
I personally think it is so incredibly stupid that DNS can match an IP address or the HostName FROM ANOTHER DOMAIN.... it finds the record but it won't give you back the FQDN of the record WHICH IT APPEARS TO KNOW WHEN YOU LOOK AT THE RECORD, IT APPEARS TO BE RIGHT THERE! ... but you can't have it unless you hardcode a list of DNS Suffixes and then you get the FQDN back which then makes the code work properly. Very poor performance indeed!
//Once you add Alpha.ca to the DNS Suffix List on the machine running this code....
//This will now correctly return Win7-Alpha.Alpha.ca
Dns.GetHostEntry("Win7-Alpha").HostName;
As I come across issues when testing my current application, I often have to tweak the database the app uses. After losing important changes several times, I wrote a program that will back up my database to a file and then check the file into SubVersion. I have found that that backup application is not good enough.
The database is a PostgreSQL database, and my backup application invokes pg_dump to create the backup file. pg_dump is executed in a console window. When the database was on my own machine, it worked well. But when I moved the database to our test server, pg_dump asked for a password. While it's not that big a deal, I'd like to be able to supply the password automatically, since it is available in the backup application.
I've tried to follow advice I've found here, but pg_dump still stops and asks for a password. Here's the code that I thought should have supplied the password:
Process backupProcess = new Process();
backupProcess.StartInfo.UseShellExecute = false;
backupProcess.StartInfo.RedirectStandardInput = true;
backupProcess.StartInfo.FileName = dumpPath + "pg_dump.exe";
backupProcess.StartInfo.Arguments = " --host " + host +
" --port " + port +
" --username " + userName +
" --format custom --blobs --verbose --file " +
"\"" + txtBackupFile.Text + "\" " + dbName;
backupProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
backupProcess.Start();
StreamWriter standardInput = backupProcess.StandardInput;
standardInput.WriteLine("mypassword");
backupProcess.WaitForExit();// Waits here for the process to exit.
Thank you for your help.
RobR
I have solved this by using
backupProcess.EnvironmentVariables["PGPASSWORD"] = "password";
This way, I avoid the password will be stored on the computer
Maybe it's cheating a little bit (in the sense that it doesn't really help you answer the question of how to feed input to pg_dump), but you could refer to this answer which suggests the use of a .pgpass file. It would certainly be possible to write to this file dynamically rather than try to interact with the program once it prompts.
Info on .pgpass here.
I'm writing an app in C# to prevent some executable file from opening. My app will detect opening selected executable file and show message box to let user choose to run it or not.
REGEDIT4
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe]
"Debugger"="calc.exe"
I have use above method from This topic but it will block all executable file with that name from any path. Which I want is to block only executable file in flashdrive or specifed path.
Example. I selected that my program will show message box when "a.exe" in Drive F:/ is opening. If I use a method in reference topic, it will block all "a.exe" in any path like "C:/a.exe", "D:/a.exe" or "F:/a.exe" but I want it to block only a.exe in F:/ not in other path or drive.
Any idea for this?
Thanks a lot.
Additional information:
Easy understanding with this question is...
I want my program to block some exe in specified path. When user try to open specified exe, my app will block it and have a message box to alert user. If user click "No", specify exe will not run but If user click "Yes", specify exe will run normally.
this will work like a anti virus software when user accidentally run virus file, Anti virus will block it and have some message to ask user that he still wanted to run it or not.
I have a similar point in a blog article where I try to detect the creation and destruction of a process instance. For this I use ManagementEventWatcher and this class uses queries like
internal ManagementEventWatcher WatchForProcessStart(string ProcessName)
{
string Query = "SELECT TargetInstance" +
" FROM __InstanceCreationEvent " + "WITHIN 2 " +
" WHERE TargetInstance ISA 'Win32_Process' " +
" AND TargetInstance.Name = '" + ProcessName + "'";
string Scope = "\\\\.\\root\\CIMV2";
ManagementEventWatcher Watcher = new ManagementEventWatcher(Scope, Query);
Watcher.Start();
return Watcher;
}
The scope is a ManagementScope instance which can be manipulated for your purposes as seen at MSDN
ManagementScope scope =
new ManagementScope(
"\\\\FullComputerName\\root\\cimv2");
scope.Connect();
I hope this helps you a bit. More information
http://msdn.microsoft.com/en-us/library/system.management.managementscope.aspx
http://www.idipous.net/how-to-monitor-proccess-creation-with-c/
After the user logins in the program, I want that my program remembers the username of the last user and when the program reopens, the username filed is filled automatically with the username of that last user.
I want to know how to save and restore username.
I dont want to use a database.
A better solution than temporary files is simply to use application settings.
To set the last username:
Properties.Settings.Default.LastUsername = theUsername;
Properties.Settings.Default.Save();
Then you can access Properties.Settings.Default.LastUsername any time you want to use the last username.
System.IO.File.WriteAllText(path, Environment.UserName);
System.IO.File.ReadAllText(path);
Something like that should work i did not wrote the code.
i write the code in asp.net using c# to delete the file in my computer, but it is not deleting please help me thank u. this is my code, i write in button click event
string path = "E:\\sasi\\delt.doc";
FileInfo myfileinf = new FileInfo(path);
myfileinf.Delete();
public void DeleteFileFromFolder(string StrFilename)
{
string strPhysicalFolder = Server.MapPath("..\\");
string strFileFullPath = strPhysicalFolder + StrFilename;
if (IO.File.Exists(strFileFullPath)) {
IO.File.Delete(strFileFullPath);
}
}
In order to delete a file you must ensure that the account has sufficient permissions. In general ASP.NET applications run under limited permission account such as Network Service. For example if your application runs under IIS 6 you could go to the Administration Console and set a custom account in the application pool properties:
alt text http://i.msdn.microsoft.com/Bb969101.SharePoint_SQL_TshootingFig3%28en-US,SQL.90%29.jpg
You need to ensure that the account is member of the IIS_WPG group.
Make sure the ASP user has permissions to this folder. By default this user is not given access to much of the harddrive..