Windows: Open program in specific screen location - windows

At work, I have a set of batch files and scripts which I use to automate all the programs I need to open in the morning (and others to close them all down at night) in order to save time and effort. The problem is, the windows all open in whatever location they so choose, since most of the information is cleared out overnight on the Virtual Desktop.
I have seen people talking of desktop managers and additional programs that make such tasks easier, but due to the restrictions at play, I do not have the ability to install programs like that. I also do not have access to edit registry files, and I can never be sure if the registry files will stay the same or be wiped and reimaged at night. So re-opening at the stored previous location seems to be out. This means that AutoHotKey , cmdow , and most .exe program options are out of the running.
Essentially what I am looking for is a way to reposition open windows, or open windows in a specific position, using either batch files or vbs. Preferably with a location relative to the screen rather than other windows, as I use multiple monitors.
I'm open to using powershell or potentially other options, but those would likely fall outside my experience. It seems like what I'm asking is either nonexistent or impossible, but I'm hoping maybe someone has an idea. I don't mind complicated code, but I have no idea where to begin on this one guys, any suggestions?

It look like someone as already answer that kind of question here :
Other post on set many programs window size and position
You can also use C# and map powershell on it using cmdlet in powershell and c# as backend. Here is an exemple in c# and just google how to make cmdlet in powershell.
Example in c#

Batch files can't do this. A VBScript can sort of do this using Windows Script Host Object Model.
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run(strCommand, [intWindowStyle: See below], [bWaitOnReturn: TRUE/FALSE])
Set WshShell = Nothing
intWindowStyle values:
0 - Hides the window and activates another window.
1 - Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
2 - Activates the window and displays it as a minimized window.
3 - Activates the window and displays it as a maximized window.
4 - Displays a window in its most recent size and position. The active window remains active.
5 - Activates the window and displays it in its current size and position.
6 - Minimizes the specified window and activates the next top-level window in the Z order.
7 - Displays the window as a minimized window. The active window remains active.
8 - Displays the window in its current state. The active window remains active.
9 - Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.
10 - Sets the show-state based on the state of the program that started the application.
Not sure about PowerShell. :/

Related

Managing windows when local SAS session starts

When a SAS session starts, there are 5 windows. (Result Viewer, Explorer, Log, Editor, Output).
My desired state is when the session starts:
No result viewer
No output window
No default explorer window
The useable explorer window default open(to clarify this i attached a picture)
Good/Bad explorer window
Enchanced editor open
Log window open
So there will be 3 windows opened at session start, and i would like to resize them into 3 columns.
What i got so far:
I know the task can be done, because i was able to do this on my working computer. Unfortunately they reinstalled my windows without a word, and i lost my setup. And i did not have my autoexec/sasv9cfg file backuped. :(
I can close the output window with dm listing off command in my autoexec.
I can resize the 3 windows if i have them, with dm wdef command as well.
My biggest issue is i cant find again a DM/ODS or any kind of command, which closes the Result Viewer, and the original Explorer, and opens the normal/usable Explorer. In my faded memories i needed only 1 DM/ODS/sth command to achieve these 3 steps at once. Of course, if we can find a solution in more steps, thats also completely fine.
Big thx for any kind of help
You do not want the DMSEXP docked windows (which includes ODS Results tab) at session start up. The only way to do this programmatically is to specify the SAS system option -nodmsexp in the sas.exe command line or config.sys.
So, on my system, I set the target command on my SAS icon to be:
"C:\Program Files\SASHome\SASFoundation\9.4\sas.exe"
-CONFIG "C:\Program Files\SASHome\SASFoundation\9.4\nls\en\sasv9.cfg"
-NODMSEXP
Tweak the SAS DM session window states by placing this code in your autoexec.sas
dm 'dmsexp;tree on;next;listing off;tile vert' ;
You can also fiddle around with your session start up using the system options:
initstmt=
initcmd

RStudio lost focus when start up

When I start up RStudio on Windows, it lost focus. I have to click on it before I could input anything to the console or script window. I know that Ctrl-1 to focus on the Script Window, and Ctrl-2 to focus on the console window; however, both of these two shortcuts will work as long as I click on RStudio first.
Is there anything I need to set in RStudio?
Software Environment:
RStudio Version 0.99.446
Windows 7 Ultimate 64-bit
As a kludge, you can write a VBScript which first opens RStudio and then switches the focus to it:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.CurrentDirectory = "C:\Program Files\RStudio"
WshShell.Run """C:\Program Files\RStudio\bin\rstudio.exe"""
WScript.Sleep 200 'milliseconds
focused = WshShell.AppActivate("RStudio")
i = 1
Do While Not focused And i < 10
WScript.Sleep 100
focused = WshShell.AppActivate("RStudio")
i = i + 1
Loop
Save this to the desktop in a file with a name like ToRStudio.vbs. Then, when you click on the icon, it opens up Rstudio and then tries to repeatedly switch focus to the RStudio window. In my original version of the code, I relied on a fixed time delay before issuing a single call to AppActivate. But, I discovered that when my workspace saved from my last session was large then my VBScript would finish executing before RStudio was ready. With the above loop, it repeatedly tries to grab focus before timing out. Since I put in the loop, it has had a 100% success rate in opening RStudio with the proper focus. In some debugging code I removed, the variable i never once got above 3 in 10 consecutive attempts.
Obviously, you might have to change the path names, and tweak the timings.
In my comment above I said that certain things about how RStudio handled focus struck me as counterintuitive. Since then I discovered RStudio's option to automatically switch focus to console on sourcing. The lack of doing this by default is what I had in mind. The issue in this question was the only remaining focus issue for me. I'm somewhat used to it by now, so I'm not sure if I'll actually use this VBS script.

Windows batch start up script to move windows

I'm experienced with many different programming languages. I decided to expand my horizons and try some simple batch scripts. I have a windows start up script that I'm running.
startupScript.bat
start "" "explorer.exe"
start "" "explorer.exe"
start "" "taskmgr.exe"
start "" "cmd.exe"
start "" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
Works great. I would like to be able to move the windows where I want them though. I'm running 5 monitors, and I want the two explorer windows on my bottom left monitor each taking half the screen. I want the command prompt and task manager in my top left monitor each taking half of the screen, and I want my chrome browser on my bottom right monitor taking up the whole screen.
Chrome remembers where it was, so that isn't a problem. The other windows don't though.
Is there a way for me to run keystrokes after each program is started? I could do "winkey+left", "winkey+left", etc... for each window if that's possible. Otherwise how might I accomplish this?
Also, when the command line is run, the properties go to defaults. Is there a way to use my command line settings so that it is sized right, has quick edit mode enabled, and has the colors that I set it to?
I'd try setting up a shortcut to the application with shortcut/Run=normal window; layout and hues to taste. Then start the shortcut (.lnk file) in your batch. Certainly works for cmd - can't say for the others...
I would have a look at AutoHotKey. I don't remember enough to tell you what your script should look like, but the little I remember tells me all you need is in their toolbox.

How to get the windows applications original size when it is first opened from window handle?

Say I open paint.exe from a c++ code using windows apis or just by clicking it.
After app opened up. I resized it(by hand or programmaticly) . And closed the app.
Next time I open it, it gives me the size from where I left off.
Is there a place where I can query the default size of apps(sizes when you see the apps when you first open it (for the very fist time) before you re size any windows)
And If i can, maybe I can call SetWindowPos to set the original position for that app.
Maybe this is not exactly a programming question.
This is always going to be different between applications.
Most application will remember their window size/position by using the registry. In the case of "paint", it stores this information in the registry at:
HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Paint\View
Notepad stores similar information in HKCU\Software\Microsoft\Notepad - in an entirely different schema of registry key values.

Windows: Language Bar will not show input method options for some of my windows

I am trying to make our application properly handle international input. Since we handle text input and font rendering ourselves, I wrote custom code to handle the respective WM_IME_* messages.
Now, this all works fine, with one exception: When our applications main window is open, the Language Bar will not let me pick any options. I can set the input language to Japanese or Korean, but the menus for choosing the input methods (like Hangul or Hiragana) are not shown. Then, when I open another window (any other window, be it one of our application windows, or a standard "save file" dialog), the options appear. Once there, they will stay, even if I close the other window. IME input will then work as expected in the main window. But, as explained, only if I open another window first.
Now, how does windows decide whether it should display the input method options or not? It appears that windows does not recognize our main window as Unicode capable for some reason. How can I fix that?
Thanks in advance for any suggestions,
jonas
Edit: One more strange thing i noticed is that for my main window (which will not let me change input methods), I will get a WM_INPUTLANGUAGECHANGEREQUEST message when i change the input language - which I pass on to DefaultWindowProcW. For the windows which let me change the input method, i don't get the request, i just get a WM_INPUTLANGUAGECHANGE message (which I don't get for the other window).
Ok, after a long search I've been able to find out what is breaking this. We are calling SetFocus on a child window in response to WM_FOCUS messages, so that a specific child window always gets focused when a window is brought to the front. Apparently, this confuses window's IME code, and makes it unaware that the window can handle IME input.
Some notes
Text Service is works per window, not system wide, so even its turn on in one window, another window will still need to turn it on, (unless user set it as default)
And Text Service is not working in any windows, to enable that, target computer need to enable following setting on

Resources