RDP - End session without losing screen resolution - remote-desktop

I have a Virtual Machine hosted elsewhere in the world.
What I want to do is to disconnect from this RDP session without:
Windows locking automatically
Screen resolution changing
I've solved the first issue of the windows locking by running this .bat file to end the session:
for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
%windir%\System32\tscon.exe %%s /dest:console
)
However, when I run a script remotely to check the screen resolution, it drops down to 1614x834.
How can I explicitly set 1920x1080?

Try that:
Install software Remote desktop(I use "Ultraview") in your Virtual Machine
After running that command, remote to Virtual Machine with that installed software and then adjust the screen resolution to 1920x1080
Can exit the software when the configuration is complete, It does not affect the process
This worked for my project :3

Related

Install a network printer with a batch file

I need to connect a lot of computers to a network printer, and I would like to send a simple batch file that do that instead of explain to each one how to use the windows wizard.
I searched on microsoft documentation and so far I can install a printer by using the printui.dll library, but only if I'm going through another computer, example:
I installed the printer through the wizard on a computer called PC1, and I set it in sharing mode, the name of the printer is PRINTER1
I can now run the command:
rundll32 printui.dll, PrintUIEntry /in /n\\PC1\PRINTER1
The problem is that in a configuration like that, if I delete the printer on PC1, every other computer will lose it too, and I can't figure out how to install the printer with his IP.
I would like something like that:
rundll32 printui.dll, PrintUIEntry /in /n 216.1.32.75 /m "Lexmark W812 (MS)" /b MY_PRINTER
When 216.1.32.75 is the printer ip, Lexmark W812(MS) is the driver needed and MY_PRINTER is the local alias of the printer.
All the computers are based on Windows 8.

Self-Elevating Batch file (non-Admin user)

We're having an issue with our Mobile Broadband modem reconnecting after a drop. The issue has been elevated but a solution may take a while. A quick work around we found is disabling and re-enabling the device, however the security settings are such that our users can't enable/disable network adapters in Network Connections.
I created a batch file to handle the disable/enable but would like it to self-elevate for a non-Admin user. Even if I have to hardcode a local admin account into the file and convert it into an executable to hide the code. Here's what I have so far:
#echo off
echo Please wait while the Sprint modem is reset...
wmic path win32_networkadapter where name="Sierra Wireless Mobile Broadband Network Adapter" call disable
timeout /t 5 /nobreak
wmic path win32_networkadapter where name="Sierra Wireless Mobile Broadband Network Adapter" call enable
This works perfectly if I chose Run As: Admin. I really appreciate any and all help.
I've had a similar problem and solved it with the help of the windows task scheduler.
Create a new task within the scheduler which simply runs the bat file.
Select a an admin user as the acount to run the task with.
Enter the password (here is the big advantage - you don't need to store it in some script as plain text)
Create another bat file with the following content: schtasks /Run /TN <taskname>
Run the new bat file.
If this doesn't work, it might be because of the user nither has permission to run tasks. In this case you'll still have to store the credentials as plain text but
schtasks /Run /U <username> /P <password> /TN <taskname>
will do the trick.

Batch file editing Hosts file - no effect?

I made a small batch file to edit the hosts file:
#echo off
title Edit Hosts
color 0A
echo Warning: Please ensure you are running this program as an administrator.
set /p admin=Type Y or N and hit enter to continue.
echo.
IF '%admin%'=='Y' goto :edithosts
IF '%admin%'=='N' exit
:edithosts
cls
set /p block=Enter website to block:
echo 127.0.0.1 %block% > C:\WINDOWS\system32\drivers\etc\hosts
pause
The file does its job and adds whatever the user types in to the hosts file in the format
127.0.0.1 website
I checked to see if the websites were listed, and the hosts file is updating correctly. However, my browser can still connect. Is this somehow due to a cached copy of the site, or is there a flaw in the code?
While changes to the hosts file are immediate on Windows for quite a while, applications may or may not be affected immediately by it. Web browsers in particular will usually cache DNS lookups to save time for further requests. This cache is most easily cleared by simply restarting the browser. After you have done that, and the DNS lookup happens, it should pick up your modified IP instead.
Newer versions of windows have default setting in Windows Defender to protect the hosts file. If you are on W8 or higher, you may also need to open Defender and add the hosts file to your exclusion list.
It's on the settings tab, click Excluded Files and Locations. Disregard red arrow, re-purposed an image from bing.

Closing an application and having it trigger a batch file to run?

I'm trying to configure a virtual machine to start up from the machine being powered on. I have that working. Now I want to be able to shut down the entire machine once someone clicks Shutdown on the start menu of the virtual machine.
I'm using VMware with Windows 7 images, if that helps.
Thank you!
invoke the start of the virtual machine with some kind of wait option and invoke shutdown afterwards.
Something like this
start /wait vmware-cmd cfg.vmx start
shutdown -s
I don't have any vmware installed, I can't test it right now so I can't make sure the vmware-cmd doesn't return right away. If that is the case, then you must look for some loop mechanism in your bat file, something like
vmware-cmd cfg.vmx start
:again
vmware-cmd cfg.vmx getstate >state.txt
if (state.txt contains some string indicating still running) goto again
shutdown -s

Capture dump with adplus.vbs - wait for debugger to finish?

I have a web application, that sometimes hangs. I want to investigate the reason, and I need to get a memory dump of the process, when it hangs.
So my idea is to monitor the website, when I am detecting the hang, I want to start a .bat script which captures the memory dump, then runs IISRESET in order to restart so that the site will start responding again.
My problem is, that adplus starts another process (cdb.exe) and returns immediately. I need to wait for cdb.exe to finish, before I can run IISRESET. Is there any way to do that in a batch script ? Or, can I specify on the adplus command line, that it should not return until the memory dump has been collected ?
Regarding the second part of your question, the answer is yes: you can both (1)specify the wait on the commmand line (as long as you can access to and modify it); and (2)wait for a process to finish in a batch file.
In their simplest form, do
(1) use START /WAIT cdb parms instead of just cdb parms
(2) try FOR /F "tokens=1,2" %a in ('TASKLIST ^| FIND /I "cdb.exe"') DO #ECHO %a %b and substitute ECHO for the command you want.
To create the memory dump of your web application, the Microsoft Debug Diagnostic Tools are your best option.
You can create an "IIS Hang" rule, monitoring a specific URL, and creating a memory dump whenever no response is received within a specified number of seconds.
The Debug Diagnostics Tools will not help you with regard to restarting IIS (or your app pool), but in general the built-in Application Pool restart options should be sufficient for that. If you make sure "Enable Pinging" is set for your AppPool (on its Health tab), and you also set the other Health/Recycling parameters appropriately, your app should continue responding no matter what happens.
If not, monitoring the output folder with crash dumps from your "IIS Hang" DebugDiag rule, and restarting IIS whenever new files appear should definitely do the trick...

Resources