Solved

Restart windows and resume application process after restarting from VB.Net

Posted on 2013-01-27
14
1,308 Views
Last Modified: 2013-01-27
Hi Experts,

I have written an application with VB.Net. I need, whenever user click one of  my application button, PC will restart and windows will start my application at the startup and the remaining process from my application will resume.

How to do this from VB.Net for Windows XP & 7?

Kindly help,

Regards,
Soumen
0
Comment
Question by:Soumen-Roy
  • 8
  • 6
14 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 38824081
Startup folder location:

win7 -
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup

winxp -
C:\Documents and Settings\All Users\Start Menu\Programs\Startup

in your vb.net exe, in the 1st phase before reboot, create a batch script and place it in the above location depends on the OS.

the script should contain the full path of your vb.net exe and pass an argument the app which will indicate running from startup.

for example:

c:\files\myapp.exe "startup"

in your app, check for this argument in Main function, and continue the remaining process of the application.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38824084
0
 

Author Comment

by:Soumen-Roy
ID: 38824091
@sedgwick,

Wow !!! Just as I expected. One little query, may I prevent user to do anything after the restart and until the process ends?

Actually if I run my process right after the boot menu and then windows opens / initialize, my target will be achieved. Is it possible?

Regards,
Soumen
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38824095
how long should take the 2nd part of the processing in your app?
0
 

Author Comment

by:Soumen-Roy
ID: 38824125
may be 40 mins to 1 hour. it is a back up process of entire system volume. but if user changes between the back up process, problem will arise. thats why i want to prevent user to do anything at time of the process running. Is it possible?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38824139
you can disable mouse and keyboard but i think splash screen with message "Back up process, do not touch", would be enough:

Splash Screen VB.NET
0
 

Author Comment

by:Soumen-Roy
ID: 38824188
Done, if mouse & keyboard can be disabled then my job is over. But how to disable those two?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 42

Expert Comment

by:sedgwick
ID: 38824210
the fastest way of doing this is to download autoit from:
AutoIt

and run the following to disable mouse & keyboard:
BlockInput(1);

to enable mouse & keyboard:
BlockInput(0);
0
 

Author Comment

by:Soumen-Roy
ID: 38824278
I downloaded that, seems very interesting, but can't understand how to integrate with my VB.Net code. Can any dll to be referenced? Any light on that, please?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38824298
you can either create 2 autoit scripts:
one with the line: BlockInput(1);
and the other with the line: BlockInput(0);

or convert your autoit script to exe and allow to accept parameter (disable/enable)
and inside the autoit exe check the parameter to call BlockInput with 1 or 0.

in your vb.net exe after reboot, you run the exe/script with the right parameter to block user input, and after backup process is done you run it again with the enable parameter.
0
 

Author Comment

by:Soumen-Roy
ID: 38824309
oO, give me some time to learn how to create autoit script, please, i have no idea regarding this

:-(
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 38824319
i created the script for you, save it as user_input.au3 file.


;check if param is available
If $CmdLine[0] = 0 Then Exit (1)

;if "disable", then disable mouse+keyboard
if $CmdLine[1] = "disable" then
	BlockInput(1)
else
	;check if "enable", then enable mouse+keyboard
	if $CmdLine[1] = "enable" then
		BlockInput(0)
	EndIf
EndIf

Open in new window


compile the script to exe and run it from your vb.net code:
to disable user input:
Process.Start("user_input.exe", "disable")

Open in new window


to enable user input:
Process.Start("user_input.exe", "enable")

Open in new window

0
 

Author Closing Comment

by:Soumen-Roy
ID: 38824333
You guys are always proven as god to me :-).

Thanx :-)
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38824338
you welcome, good luck :)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now