Solved

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

Posted on 2013-01-27
14
1,341 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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
 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

815 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

7 Experts available now in Live!

Get 1:1 Help Now