Jump to content

How to delay part of a function


Recommended Posts

I have this function here, which works properly:

Sub RunFull
Set objShell = CreateObject("WScript.Shell")
objShell.Run "fscommand\full.exe"
On Error Resume Next
Set objShell = Nothing
Call confirmation2()
End Sub

However, the problem is that the last item, "call confirmation2()" happens right away. In other words, I need it to have the following procedure:

1. run full.exe

2. when full.exe is done, call confirmation2()

What happens is that it runs full.exe, and then executes the call. This confirmation makes a msgbox appear on the screen.

In addition, it may be helpful for me to have it do 3 things, but I do not have the code for it.

1. run full.exe

2. while full.exe is running, show an animation or splash screen

3. when full.exe is done, hide the splash screen and call confirmation2()

I'm currently trying to get AutoIT to display the splash screen while it is running, but it isn't working out properly.

Link to comment
Share on other sites


Hide the default window and keep focus until finished

objShell.Run "fscommand\full.exe", 0, true

Show the default window and keep focus until finished

objShell.Run "fscommand\full.exe", 1, true

I was bored so I made you a Hta that acts like a splash screen,

just uncomment the below code in the hta

   ' CreateObject("WScript.Shell").Run("fscommand\full.exe"),0,True

Place the code for that function here

	'-> Place Your Code For confirmation2 Here Start

'-> Place Your Code For confirmation2 Here End

This uses a Three second stop before it process the next timer of Three seconds then it closes it self.

Save As MySplashScreen.hta

  <Title>Fs Command Hta</Title>
<HTA:APPLICATION ID="FsSplashScreen"
SCROLL="No"
SCROLLFLAT ="No"
SingleInstance="Yes"
ShowInTaskbar="No"
SysMenu="No"
MaximizeButton="No"
MinimizeButton="No"
Border="Thin"
BORDERSTYLE ="complex"
INNERBORDER ="No"
Caption="Yes"
WindowState="Normal"
APPLICATIONNAME="FsCommandHta"
Icon="%SystemRoot%\explorer.exe">
<STYLE type="text/css">
BODY
{
Font:9.25pt;
Font-weight:bold;
Font-family:helvetica,verdana,arial;
Color:#000080;
Text-Align:Center;
Vertical-Align:Middle;
filter:progid:DXImageTransform.Microsoft.Gradient(StartColorStr='#E2E2E2',EndColorStr='#6e6e6e);
Padding-Top:3;
Padding-Bottom:2;
Padding-Left:10;
Padding-Right:10;
}
</STYLE>
<script Language='VBSCRIPT'>
'-> Resize And Move Window
Dim Wth :Wth = int(425)
Dim Hht :Hht = int(175)
window.ResizeTo Wth, Hht
MoveTo ((Screen.Width / 2) - (Wth / 2)),((Screen.Height / 2) - (Hht / 2))
Dim Tmr
'-> Start The First Timer OnLoad, Three Second Wait Befor It Goes
'-> To The ClearTimer Function
Function Window_OnLoad()
document.focus()
Txt1.innerHTML= "Processing The Script Function Please Wait"
Tmr=setTimeout("ClearTimer()",3000)
Exit Function
End Function
'-> Process The First Command
Function ClearTimer()
'-> Object To Run The First Command Hidden, Uncooment To Make Active
' CreateObject("WScript.Shell").Run("fscommand\full.exe"),0,True
Tmr=clearTimeout("")
'-> Place Your Code For confirmation2 Here Start

'-> Place Your Code For confirmation2 Here End
Txt1.innerHTML= "Completed FsCommand Prepaparing To Close"
Tmr=setTimeout("ClearTimer2()",3000)
Exit Function
End Function
'-> Close The Hta Function
Function ClearTimer2()
Tmr=clearTimeout("")
window.close()
Exit Function
End Function
</SCRIPT>
<BODY Scroll='No'><TABLE><SPAN ID='Txt1'> </SPAN></TABLE></BODY>

Link to comment
Share on other sites

Actually, I'm having some trouble figuring this out. I have an existing HTA that needs to run this command. How do I wrap that code into a function? Also, there is the "confirmation2" code:

Sub confirmation2
Dim Answer
Answer = window.confirm("Recovery Complete, Would you like to Restart now?")
If Answer Then
objshell.run("wpeutil Reboot"),0
Else

End If
End Sub

Currently the full.exe is triggered from the input element OnClick. And even now, I may not even want it to run full.exe. Full.exe is made in AutoIT but has since stopped working for me. Here is it's code. I am pretty sure I can just have the HTA do these commands, since I do have Geezery's HTA to use as a reference. It's just tough for me jumping into VBScript, I am not used to it. :unsure:

RunWait (@ComSpec & " /c x:\windows\system32\diskpart /s x:\windows\system32\full_diskpart.txt", @SW_HIDE)
RunWait (@ComSpec & " /c imagex /apply c:\sp1.wim 1 d:", @SW_HIDE)

Link to comment
Share on other sites

Change this

Sub confirmation2
Dim Answer
Answer = window.confirm("Recovery Complete, Would you like to Restart now?")
If Answer Then
objshell.run("wpeutil Reboot"),0
Else

End If
End Sub

Sub confirmation2
Dim A1 :A1 = window.confirm("Recovery Complete, Would you like to Restart now?")
If A1 = True Then CreateObject("WScript.Shell").Run("wpeutil Reboot"),0
End Sub

Or here is a hta with the button sub added to it

  <Title>Fs Command Hta</Title>
<HTA:APPLICATION ID="FsSplashScreen"
SCROLL="No"
SCROLLFLAT ="No"
SingleInstance="Yes"
ShowInTaskbar="Yes"
SysMenu="Yes"
MaximizeButton="No"
MinimizeButton="Yes"
Border="Thin"
BORDERSTYLE ="complex"
INNERBORDER ="No"
Caption="Yes"
WindowState="Normal"
APPLICATIONNAME="FsCommandHta"
Icon="%SystemRoot%\explorer.exe">
<STYLE type="text/css">
BODY
{
Font:9.25pt;
Font-weight:bold;
Font-family:helvetica,verdana,arial;
Color:#000080;
Text-Align:Center;
Vertical-Align:Middle;
filter:progid:DXImageTransform.Microsoft.Gradient(StartColorStr='#E2E2E2',EndColorStr='#6E6E6E');
Margin-Top:2;
Margin-Bottom:2;
Margin-Left:2;
Margin-Right:2;
Padding-Top:2;
Padding-Bottom:2;
Padding-Left:9;
Padding-Right:9;
}
BUTTON
{
Height:18pt;
width:69pt;
Cursor:Hand;
Font:8.05pt;
Font-weight:bold;
Font-family:helvetica,verdana,arial;
Color:#404040;
Text-Align:Center;
Vertical-Align:Middle;
filter:progid:DXImageTransform.Microsoft.Gradient(StartColorStr='#E5E5E5',EndColorStr='#7D7D7D');
Margin-Top:1;
Margin-Bottom:1;
Margin-Left:1;
Margin-Right:1;
Padding-Top:2;
Padding-Bottom:2;
Padding-Left:2;
Padding-Right:2;
border-left: 1px Transparent;
border-right: 2px Transparent;
border-top: 1px Transparent;
border-Bottom: 2px Transparent;
}
</STYLE>
<script Language='VBSCRIPT'>
'-> Resize And Move Window
Dim Wth :Wth = int(431)
Dim Hht :Hht = int(179)
window.ResizeTo Wth, Hht
MoveTo ((Screen.Width / 2) - (Wth / 2)),((Screen.Height / 2) - (Hht / 2))
Sub Confirmation2
Dim A1 :A1 = window.confirm("Recovery Complete, Would you like to Restart now?")
If A1 = True Then CreateObject("WScript.Shell").Run("wpeutil Reboot"),0
End Sub
</SCRIPT>
<BODY Scroll='No'>
<BUTTON OnClick='Confirmation2'>Button 01</BUTTON>
</BODY>

Link to comment
Share on other sites

I figured it would be easier if I get rid of the exe that the script runs, and make the HTA run those commands. I set it up so that when I click a button on the main HTA, it opens one that uses the above code. By comparing other projects, I can get this other HTA to launch via:

objShell.Run("mshta " & HTAFile),1,True

However, there are some issues. I am testing in a VirtualBox because it is faster than having to rebuild the source every time. When I click the button, a second MSHTA.EXE will execute but the second file is not visible. The above snippet is how Geezery's GImageX HTA launches the diskpart.hta file, and it works fine there. I can open the file manually and it appears to be normal. However, since I am running in a VM the actions it attempts to take fail (because the path to imagex, for example) does not exist in the VM. So I can't figure out why it is hiding the new HTA. Here are some code peices.

First, this is the subroutine used to launch the HTA from a button. This code can launch other EXEs or commands just fine.

Sub RunRepair
Set objShell = CreateObject("WScript.Shell")
ObjShell.Run("mshta repair.hta"),1,True
On Error Resume Next
Set objShell = Nothing
End Sub

I am nearly finished. Soon I can move this into in-house beta and get the software put through the corporate branding and approval process. :thumbup

Link to comment
Share on other sites

If you know the diskpart commands you're going to run, I suggest the following:

Sub RunFull
Set objShell = CreateObject("WScript.Shell")

cmd = "%comspec% /c diskpart /s X:\windows\system32\full_diskpart.txt"
objShell.Run cmd,0,1 ' Run the command in a hidden window and wait for a return

cmd = "%comspec% /c imagex /apply c:\sp1.wim 1 d:\"
objShell.Run cmd,0,1

valAnswer = msgbox("Recovery Complete. Would you like to Restart now?",vbYesNo,"Restart now?")
If valAnswer = vbYes Then
cmd = "wpeutil reboot"
objShell.Run cmd,0,1
End If

End Sub

Link to comment
Share on other sites

Getting it to run from the main HTA is not a problem. I need to have some sort of splash screen or animation to be displayed while it is running diskpart, as well as while it is running imagex. This is why I changed to launch a separate HTA that runs those commands. Once I can get that small HTA to run properly, I can insert an animated GIF or something into there.

Link to comment
Share on other sites

Try this HTA and see if it does what you want.

  <Title>Main Application Name</Title>
<HTA:APPLICATION ID="MainApplication"
SCROLL="No"
SCROLLFLAT ="No"
SingleInstance="Yes"
ShowInTaskbar="Yes"
SysMenu="Yes"
MaximizeButton="No"
MinimizeButton="No"
Border="Thin"
BORDERSTYLE ="complex"
INNERBORDER ="No"
Caption="Yes"
WindowState="Normal"
APPLICATIONNAME="MainApp"
Icon="%SystemRoot%\explorer.exe">
<STYLE type="text/css">
BODY
{
Font:9.25pt;
Font-Weight:bold;
Font-Family:helvetica,verdana,arial;
Color:#000080;
Text-Align:Center;
Vertical-Align:Middle;
Filter:progid:DXImageTransform.Microsoft.Gradient(StartColorStr='#E2E2E2',EndColorStr='#6e6e6e);
Padding-Top:3;
Padding-Bottom:2;
Padding-Left:10;
Padding-Right:10;
}
BUTTON
{
Height:18pt;
width:69pt;
Cursor:Hand;
Font:8.05pt;
Font-weight:bold;
Font-family:helvetica,verdana,arial;
Color:#404040;
Text-Align:Center;
Vertical-Align:Middle;
filter:progid:DXImageTransform.Microsoft.Gradient(StartColorStr='#E5E5E5',EndColorStr='#7D7D7D');
Margin-Top:1;
Margin-Bottom:1;
Margin-Left:1;
Margin-Right:1;
Padding-Top:2;
Padding-Bottom:2;
Padding-Left:2;
Padding-Right:2;
border-left: 1px Transparent;
border-right: 2px Transparent;
border-top: 1px Transparent;
border-Bottom: 2px Transparent;
}
TD
{
Margin-Top:1;
Margin-Bottom:1;
Margin-Left:1;
Margin-Right:1;
Padding-Top:1;
Padding-Bottom:1;
Padding-Left:1;
Padding-Right:1;
}
DIV.Dialog
{
Height:48pt;
width:225pt;
Color:#005200;
Text-Align:Center;
Vertical-Align:Middle;
filter:progid:DXImageTransform.Microsoft.Gradient(StartColorStr='#A3D9A3',EndColorStr='#2a5c2a');
Border-Top:2px Solid #cbc7c3;
Border-Bottom:3px Solid #a6a29e;
Border-Left:2px Solid #bcb8b4;
Border-Right:3px Solid #b2aeaa;
Padding-Top:3;
Padding-Bottom:2;
Padding-Left:10;
Padding-Right:10;
}
</STYLE>
<script Language='VBSCRIPT'>
'-> Resize And Move Window
Dim Wth :Wth = int(425)
Dim Hht :Hht = int(175)
window.ResizeTo Wth, Hht
MoveTo ((Screen.Width / 2) - (Wth / 2)),((Screen.Height / 2) - (Hht / 2))
'-> Varibles And Objects
Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Tmr
'-> Button 01 Clicks Action Start
'-> Show The First Dialog Message
Function ShowDialog1()
If Info1.style.visibility = "hidden" Then
Info1.style.visibility = ""
Info1.innerHTML = "<FONT STYLE='COLOR:#DE4545'>Processing Test Message 01a</FONT><DIV>" & _
"This Will Take A Few Minutes To Process</DIV>"
Tmr=setTimeout("DialogTimer1a()",5000)
End If
Exit Function
End Function
'-> Second And Third Dialog Messages
Function DialogTimer1a()
Info1.innerHTML = "Processing Test Message 01b"
Tmr=clearTimeout("")
Act.Run("Notepad"),1,true
Info1.innerHTML ="Process Is Completed."
Tmr=setTimeout("DialogClose()",5000)
Exit Function
End Function
'-> Button 02 Clicks Action Start
'-> Show The First Dialog Message
Function ShowDialog2()
If Info1.style.visibility = "hidden" Then
Info1.style.visibility = ""
Info1.innerHTML = "<FONT STYLE='COLOR:#DE4545'>Processing Test Message 02a</FONT><DIV>" & _
"This Will Take A Few Minutes To Process</DIV>"
Tmr=setTimeout("DialogTimer2a()",5000)
End If
Exit Function
End Function
'-> Second And Third Dialog Messages
Function DialogTimer2a()
Info1.innerHTML = "Processing Test Message 02b"
Tmr=clearTimeout("")
Act.Run("Calc"),1,true
Info1.innerHTML ="Process Is Completed."
Tmr=setTimeout("DialogClose()",5000)
Exit Function
End Function
'-> Close And Clear The Dialog Popup
Function DialogClose()
Tmr=clearTimeout("")
Info1.innerHTML =""
Info1.style.visibility = "hidden"
Exit Function
End Function
</SCRIPT>
<BODY>
<TABLE Border='1'>
<TD><BUTTON ID='Btn01' OnClick='ShowDialog1()'>Button 01</BUTTON></TD>
<TD><BUTTON ID='Btn02'OnClick='ShowDialog2()'>Button 02</BUTTON></TD>
</TABLE>
<!-- Dialog That Gets Displayed -->
<DIV ID='Info1' Class='Dialog' Style='Visibility:Hidden;Position:Absolute;Left:62;Bottom:11;'>
</DIV>
</BODY>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...