How to run msg.exe after opening a shell using cmd.exe - vb.net

I want to send messages withing a windows 7 LAN using VB.NET code. The problem is that the msg.exe executes commands in admin mode only. Here is the code.
Shell("cmd.exe /k runas /user:farook-pc\administrator msg.exe") 'Here i'm prompted for a password.
Shell("cmd.exe /k msg.exe", 1)
I use the /k switch to see what's going on in the shell. /c is the silent switch. I do not wish to use runas neither do I wish to change privilages in msg.exe

I hate launching other apps and trying to control them like that. If possible, I would recommend trying to mimic the functionality of msg.exe, yourself, programatically. From doing a few quick google searches, I found that the API function that msg.exe uses is apparently WTSSendMessage in Wtsapi32.dll. Here's the MSDN article on that function:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa383842(v=vs.85).aspx
And here's a link that shows how to invoke that API function from .NET:
http://www.pinvoke.net/default.aspx/wtsapi32/wtssendmessage.html
I've never used it before, or even heard of it before, so, unfortunately, I can't help you beyond that.

Its possible to start the VB.NET application automatically in admin mode.
That can be changed in the project-settings.
After that you can open msg.exe with the following command:
Shell("msg.exe")

Related

How to identify any application exe is launched or not?

I want to know .exe file is getting properly launched or not?
I want a wrapper(in LabVIEW) to check whether the launching is done successfully or not.
Thanks in Advance:)
You can use SysExec.vi to launch other applications from LabVIEW. You can refer this link
Then again use SysExec.vi with the command "cmd /c tasklist" to get the active application list. From the standard output you can find the target application.

Running PowerShell with different user

Can anyone help me with run command to open PowerShell as different user?
Currently I am trying to run below command
Runas /noprofile /user:domain\username powershell
It works but I have to provide password once powershell window opens, is there any way where I can directly put password in run command?
Or even if I get to know how can I run any commands from PowerShell using different user without opening new ps window. e.g need to run below command using different user.
Restart-Server -Name testservice
You could try schtasks.exe. You can get the help using schtasks.exe /?
If you are getting any errors after using this command referring the examples, update the post with the error, we are here to help you.
Update:
There is an in-built cmdlet available in PowerShell Register-ScheduledTask, but its depended on OS and is available only from Windows Server 2012 onwards.

Using WinSCP script for SFTP access from SSIS

I am new to WinSCP and am attempting to create a script file that will eventually be used with SSIS to download files from an SFTP site. A lot of the literature WinSCP includes explains the file downloading or uploading portions. For the time being, I just want to create a script to test the connection first and will build from there.
So far I saved the connection in WinSCP and have the following. The below code does not seem to function at all and I am not sure where else to go as I am still reading about the scripting for WinSCP. Is there a way or can someone point me in a direction to see if I am in fact connecting via through the script?
option batch on
option confirm off
open username#address
exit
Not sure what SSIS is (sorry) but I can tell you how I'd set it up from a windows batch file if that helps:
If you are open to using a different software, consider using cygwin. It mimics a linux shell so linux users on windows have a lot of linux utilities handy. That being said, there are some commands which can run on windows straight from command prompt (and thus batchable). What you'd need to do:
1) install cygwin
2) Create a "passwordless" login (using ssh-rsa authentication). To do this start your cygwin terminal and use the commands "ssh-keygen" and "ssh-copy-id" (more on that later)
3) Now you can run "sftp" from the DOS command prompt (does not require cygwin terminal) and sftp to your account. No password required because of step 2).
A few follow up info:
What can run from dos command prompt and what must be run from cygwin terminal?
If you go to the "bin" directory of cygwin (for me it's in c:\cygwin\bin) you can see all the cygwin utilities. Anything with "exe" extension can be run from dos command prompt. If no "exe" extension, must start cygwin terminal first
How to set up ssh-rsa authentication?
You can pretty much google "ssh login without password" and pull up a lot of results. This is common for setting up login from one linux system to another. You would be using the same steps using cygwin on windows. My instructions are here:
http://geekswing.com/geek/unix/how-to-ssh-login-without-a-password-using-ssh-keygen-quick-tutorial/
Storing session settings in WinSCP GUI and trying to access them from WinSCP script running in SSIS is generally a bad idea. I believe there's no example or guide on WinSCP site that would suggest doing that.
WinSCP stores its configuration in registry in HKEY_CURRENT_USER hive. The SSIS typically runs under a dedicated system account, that have its own HKEY_CURRENT_USER hive, and won't see the GUI configuration.
For details see WinSCP FAQ about your problem:
https://winscp.net/eng/docs/faq_scheduler
The best you can do is isolate your your script from configuration by using the session URL with the open command, instead of the stored site name.
See also https://winscp.net/eng/docs/scripting#configuration
Your actual problem can be completely different though. But that's hard to guess as you have not shared any details, such as error message, log file, etc.

WiX Shell Command Conditional Installation

I'm new to WiX (and Windows development in general), and I'd like to add logic to my installer that will cause the installation to fail with a friendly error if the shell command fails. I've seen the ShellExecute CustomAction and instructions for Conditional Installation, but I'm not sure how to tie these together.
I prefer to write my own Custom Action in either VbScript or C# while calling API method ShellExecute. In this way, we have good control over its return code (if ShellExecute fails) and we can display our own user friend message and terminate the installation (or set it to roll back).
Here is an example not specific to ShellExecute, but how to quit from Installation while showing your own user friend message:
http://devdare.blogspot.com/2012/07/how-to-quit-installation-from-vbscript.html
For using ShellExecute in VBScript Custom Action:
http://ss64.com/vb/shellexecute.html
Hope this helps.

Detect file in use by other process

On windows and such I used to use a trick to find out of a file is currently in use (written specifically).
I use to open the file for writing and if it failed most likey another process is busy accessing it.
Sadly these trick (using C OPEN with exclusive lock for writing) doesn't work on my Mac. While my curl in a terminal is still writing my -fileBusy() check fails.
fcnt call on the fd with F_GETLK doesn't reveal any locking as well.
Is there any chance for me to detect if a file is in use by another process?
Ps> listening for fsevents can't be done because my app launches after the is created by the other app / process.
Apple confirmed via email that the solution described in the link below is a valid one and not considered a private API.
More information:
http://lists.apple.com/archives/cocoa-dev/2010/May/msg01455.html
You could try running the following shell command using NSTask:
lsof -Fc path/to/thefile
That will give you the process ID and name of any process(es) that have thefile open.