Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with carriage returns

Status
Not open for further replies.

Briandr

MIS
Jul 11, 2003
177
US
Hi Guys,

Can someone tell me what is wrong with the carriage returns below.

varRestart = oShell.Popup ("The " & sTitle & " installation has been completed successfully!" & vbCrLf _
"Your laptop needs to be restarted so it can be encrypted. You should be able to go about your work as vbCrLf _
Your laptop will encrypt in the background. Would you like to restart now to begin the process?" & vbCrLf _
This message will continuously pop up every 5 minutes until a restart has taken place" , 3600, sTitle, vbExclamation+vbYesNo+vbSystemModal)

Thank you.
 
varRestart = oShell.Popup ("The " & sTitle & " installation has been completed successfully!" & vbCrLf [highlight #FCE94F]&[/highlight] _
"Your laptop needs to be restarted so it can be encrypted. You should be able to go about your work as [highlight #FCE94F]" &[/highlight] vbCrLf [highlight #FCE94F]&[/highlight] _
[highlight #FCE94F]"[/highlight]Your laptop will encrypt in the background. Would you like to restart now to begin the process?" & vbCrLf [highlight #FCE94F]&[/highlight] _
[highlight #FCE94F]"[/highlight]This message will continuously pop up every 5 minutes until a restart has taken place" , 3600, sTitle, vbExclamation+vbYesNo+vbSystemModal)
 
Hi [thumbsup]
Try this code :
Code:
Set oShell = CreateObject("wscript.Shell")
sTitle = "Encryption Software"
Do
	varRestart = oShell.Popup ("The " & sTitle & " installation has been completed successfully!" & vbCrLf & _
	"Your laptop needs to be restarted so it can be encrypted. You should be able to go about your work as " & vbCrLf & _
	"Your laptop will encrypt in the background. Would you like to restart now to begin the process?" & vbCrLf & _
	"This message will continuously pop up every 5 minutes until a restart has taken place",20, sTitle, vbExclamation+vbYesNo)
	if varRestart = VbYes Then
		Msgbox " Restart Now ! ",48," Restart Now !"
		Call Restart()
		exit do
	else
		wscript.Sleep 300000 ' Sleep for 5 minutes
	end if
Loop

Sub Restart()
	Attente = "60" ' wait for 1 min
	Avertissement = "Your laptop needs to be restarted so it can be encrypted"
	Command = "Cmd /c shutdown.exe -r -c " & dblquote(Avertissement) & " -t " & Attente & ""
	Execution = oShell.Run(Command,0,True)
End Sub

Function dblquote(strIn)
	dblquote = Chr(34) & strIn & Chr(34)
End Function
 
Hi,

Thanks to both repliers. One thing I am trying to figure out is how to make the message box aesthetically pleasing to the eye. Right now the message box appears to be too long. The carriage returns are working, but can this be better handled with some form of vbscript word wrapping?

Thanks.
 
It's a standard MsgBox dialog... what about it is "too long"? If you don't force vbCrLf's in, it will autowrap. True, you cannot change the width but it's not clear what you don't like?

Or, you could just be less verbose and more to-the-point in your message.

Or, you could open a browser to display an HTML message (or make an HTA) from your script, if aesthetics are important and you want to expend the effort.
 
Hi ! [2thumbsup]
What about this ?
Code:
Set oShell = CreateObject("wscript.Shell")
nMinutes = 5
nSeconds = 0
sTitle = "Encryption Software"
Msg = "The " & sTitle & " installation has been completed successfully!" & vbCrLf & _
"Your laptop needs to be restarted so it can be encrypted. You should be able to go about your work as " & vbCrLf & _
"Your laptop will encrypt in the background. Would you like to restart now to begin the process?" & vbCrLf & _
"This message will continuously pop up every 5 minutes until a restart has taken place"
sMessage = "<font color=red size=3><b>"&Msg&"</b></font>"
' Open a chromeless window with message
with HTABox("lightBlue",250, 450, 400,100)
	.document.title = sTitle  & " Notification" 
	.msg.innerHTML = sMessage
	do until .done.value or (nMinutes + nSeconds < 1)
		.msg.innerHTML = sMessage & "<br>" & nMinutes & ":" & Right("0"&nSeconds, 2) _
		& " remaining<br>"
		wsh.sleep 1000 ' milliseconds
		nSeconds = nSeconds - 1
		if nSeconds < 0 then 
			if nMinutes > 0 then
				nMinutes = nMinutes - 1
				nSeconds = 59
			end if
		end if
	loop
	.done.value = true
	.close
end with

'*********************************************** process goes here ...***********************************************************"
Do
	varRestart = oShell.Popup ("The " & sTitle & " installation has been completed successfully!" & vbCrLf & _
	"Your laptop needs to be restarted so it can be encrypted. You should be able to go about your work as " & vbCrLf & _
	"Your laptop will encrypt in the background. Would you like to restart now to begin the process?" & vbCrLf & _
	"This message will continuously pop up every 5 minutes until a restart has taken place",20, sTitle, vbExclamation+vbYesNo)
	if varRestart = VbYes Then
'Msgbox " Restart Now ! ",48," Restart Now !"
		Call Restart()
		exit do
	else
		wscript.Sleep 300000 ' Sleep for 5 minutes
	end if
Loop
'********************************************** script ends here  ***************************************************************
Function HTABox(sBgColor, h, w, l, t)
	Dim IE, HTA, sCmd, nRnd
	randomize : nRnd = Int(1000000 * rnd)
	sCmd = "mshta.exe ""javascript:{new " _
	& "ActiveXObject(""InternetExplorer.Application"")" _
	& ".PutProperty('" & nRnd & "',window);" _
	& "window.resizeTo(" & w & "," & h & ");" _
	& "window.moveTo(" & l & "," & t & ")}"""
	Set WshShell = WScript.CreateObject("WScript.Shell")
	with CreateObject("WScript.Shell")
		.Run sCmd, 1, False
		do until .AppActivate("javascript:{new ") : WSH.sleep 10 : loop
		end with  'WSHShell
		For Each IE In CreateObject("Shell.Application").windows
			If IsObject(IE.GetProperty(nRnd)) Then
				set HTABox = IE.GetProperty(nRnd)
				IE.Quit
				HTABox.document.title = "HTABox"
				HTABox.document.write _
				"<HTA:Application contextMenu=no border=thin " _
				& "minimizebutton=no maximizebutton=no sysmenu=no />" _
				& "<body scroll=no style='background-color:" _
				& sBgColor & ";font:normal 10pt Arial;" _
				& "border-Style:inset;border-Width:3px'" _
				& "onbeforeunload='vbscript:if not done.value then " _
				& "window.event.cancelBubble=true:" _
				& "window.event.returnValue=false:" _
				& "done.value=true:end if'>" _
				& "<input type=hidden id=done value=false>" _
				& "<center><span id=msg>&nbsp;</span><br>" _
				& "<input type=button id=btn1 value=' Restart ' "_
				& "onclick=done.value=true><center></body>"
				HTABox.btn1.focus
				Exit Function
			End If
		Next
		MsgBox "HTA window not found."
		wsh.quit
End Function
	
Sub Restart()
		Attente = "60" ' wait for 1 min
		Avertissement = "Your laptop needs to be restarted so it can be encrypted"
		Command = "Cmd /c shutdown.exe -r -c " & dblquote(Avertissement) & " -t " & Attente & ""
		Execution = oShell.Run(Command,0,True)
End Sub
	
Function dblquote(strIn)
		dblquote = Chr(34) & strIn & Chr(34)
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top