?
Solved

HTA add image and textbox and pass parameter to one vbscript.

Posted on 2011-04-27
18
Medium Priority
?
3,395 Views
Last Modified: 2012-05-11
Guys,

I finishing this HTA file but I need help to improve with 3 requirements:

1- Add Image as picture show:
 Picture1This is the picture to attach:
 ImageToAttachAsPictureShow

2- Add a Text Area to type an URL and button to browse when Click Browse open Internet Explorer with the Page and when close the Internet Explorer ask The Web Page load fine? yes or no.
Image2
3- The Last is I need create a new Text Area (in HTA File) to write a numbers only  example: 5879226
and pass this number as parameter to this vbscript (The idea is understand how to pass a new field value to script and what I need specify in the script to receive the parameter):
 
'*******************************************************************************************************
' Tool for Automate Restore of backups in Sharepoint 2007 - Powered by Gonzalo G. Becerra
'*******************************************************************************************************

Option Explicit
Dim SiteURL, C_SiteURL, sAplic, nWO, sBackuptoRestore


Dim fso, folder, filedate, f, file
Dim sBackupPrefix

Set fso = CreateObject("Scripting.FileSystemObject")

Dim objShell
Dim strcmd
Dim runas
Dim sPwd
Dim sUserName
Dim sRestoreInetpub
Dim sRestoreFolder
Dim sFile
Dim objFSO
Dim WshShell
Dim sa
Dim filesInzip
Dim sSPSRestore
Dim sRestoreHive
Dim sHiveFolder
Dim sHiveFile
Dim sRestoreMetabase
Dim sMetabaseFolder
Dim sMetabaseFile
Dim sMetaRestore
Dim  WshNetwork
Dim strComputer

Set objShell = CreateObject("WScript.Shell")

Dim psexec, psexeccmd, objexec



'------------------------------ Restore Sharepoint (STSADM)------------------------------------------------------
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
sSPSRestore = WshShell.Popup("Restore Sharepoint STSADM?",, "IIS", 4 + 32)
	if sSPSRestore = 6 Then
		sBackuptoRestore = Inputbox("Enter the BAK File to Restore: e.g.: E:\Temp\Backups\eForms\WO_444.bak","Enter file Location" ,"")
		SiteURL = Inputbox ("Enter the URL to Restore","e.g.: http://url", "http://")
		C_SiteURL = Chr(34) & SiteURL & chr(34)
		Const C_NamePrefix = "SharePoint_"
		Const C_SharePointBin = "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Bin"
		sUserName = Inputbox("Enter the Service Account: e.g. Domain\Service Account","Enter the Service Account", "")
		sPwd = Inputbox("Enter the password for: " & sUserName,"Enter the Service Account Password", "")
		psexec = "E:\Temp\Backups\psexec.exe"
		psexec = fso.getfile(psexec).ShortPath
		psexeccmd = psexec & " -accepteula -u " & sUserName & " -p " & sPwd & " \\" & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%") & " cmd /c " 
		strcmd = fso.GetFolder(C_SharePointBin).ShortPath & "\stsadm.exe -o restore -url " & C_SiteURL & " -filename " & sBackuptoRestore &  " -overwrite"
		'Inputbox "Running command", "Command", psexeccmd & strcmd
		Set objexec = objShell.Exec(psexeccmd & strcmd)
		While objexec.Status = 0
			WScript.Sleep 100
		Wend

	else
	End if
'---------------------------------------------------------------------------------------------------------------


'------------------------------ Restore Inetpub Folder ---------------------------------------------------------
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
sRestoreInetpub = WshShell.Popup("Restore Inetpub Folder?",, "IIS", 4 + 32)
	if sRestoreInetpub = 6 Then
	   sRestoreFolder = Inputbox("Enter the Inetpub Folder to Restore","e.g.: E:\Inetpub","E:\Inetpub")
	   sFile = Inputbox("Enter the ZipFile Full Path","e.g.: E:\Temp\Backups\eforms.zip","")
	   set sa = CreateObject("Shell.Application") 
	   set filesInzip=sa.NameSpace(sFile).items 
	   sa.NameSpace(sRestoreFolder).CopyHere(filesInzip)
	else
	End if
'---------------------------------------------------------------------------------------------------------------

'------------------------------ Restore 12 Folder ---------------------------------------------------------
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
sRestoreHive = WshShell.Popup("Restore 12 Folder?",, "IIS", 4 + 32)
	if sRestoreHive = 6 Then
	   sHiveFolder = "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions"
	   sHiveFile = Inputbox("Enter the ZipFile Full Path","e.g.:  E:\Temp\Backups\application-12hive.zip","")
	   set sa = CreateObject("Shell.Application") 
	   set filesInzip=sa.NameSpace(sHiveFile).items 
	   sa.NameSpace(sHiveFolder).CopyHere(filesInzip)
	else
	End if
'---------------------------------------------------------------------------------------------------------------



WScript.Echo "Restore of site collection successful"
msgbox "Restore of site collection successful"
Set objshell = nothing

Open in new window



This is the HTA File:
 
<head>
<title>Collaboration Service Checklist</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Collaboration Service Checklist"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>
</head>

<script language="VBScript">

Option Explicit
Dim objWMIService, objItem, objService, objShell, objFSO, strLogFile, DQ, strCommand,strScript1, objFile, UserID
Dim colListOfServices, strComputer
Dim arrServices, strService, intReturn
arrServices = Array("Application Service1", "Application Service2", "Application Service3")
arrServices = Array("spooler", "spooler")
strComputer = "."     'local computer

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strLogFile = "E:\Temp\LogFile.txt"
DQ = Chr(34)
UserID = "Domain\" & CreateObject("WScript.Network").Username
strCommand = "wscript.exe "
strScript1 = "E:\Temp\Backup_SPS_PS.vbs"


Sub Check_EventVwr
	Dim Evtchk
	Const ForAppending = 8 
	Start_chk_bkp.Value = ""
	If objFSO.FileExists(strLogFile) Then
		Set objFile = objFSO.OpenTextFile(strLogFile,ForAppending,True)
	Else
		Set objFile = objFSO.CreateTextFile(strLogFile)
	End If
	
	Evtchk = objShell.Run("eventvwr")
		if Evtchk = 0 then
			objFile.WriteLine date & " " & time & " The Event Viewer was checked by " & UserID
			Start_chk_bkp.Value = date & " " & time & " The Event Viewer was checked by " & UserID
		End if
	objFile.Close

End Sub


Sub Check_SPS_Solutions_Before
	Dim obj
	Const ForAppending = 8 
	Check_Solution_Before.Value = ""
	If objFSO.FileExists(strLogFile) Then
		Set objFile = objFSO.OpenTextFile(strLogFile,ForAppending,True)
	Else
		Set objFile = objFSO.CreateTextFile(strLogFile)
	End If
	Set obj = CreateObject("InternetExplorer.Application")
	obj.navigate "http://localhost:2000/_admin/Solutions.aspx"
	obj.Visible = True
	objFile.WriteLine date & " " & time & " The solution before start was checked by " & UserID
	Check_Solution_Before.Value = date & " " & time & " The solution before start was checked by " & UserID
	objFile.Close

End Sub

Sub BackupSPS
	dim StrbkpSPS
	Const ForAppending = 8 
	BKP_Aco_Script.Value = ""
	If objFSO.FileExists(strLogFile) Then
		Set objFile = objFSO.OpenTextFile(strLogFile,ForAppending,True)
	Else
		Set objFile = objFSO.CreateTextFile(strLogFile)
	End If
	
	objShell.Run strCommand & DQ & strScript1 & DQ,1,True
	objFile.WriteLine date & " " & time & " The Backup SPS Script was Runned by " & UserID
	BKP_Aco_Script.Value = date & " " & time & " The Backup SPS Script was Runned by " & UserID
	objFile.Close

End Sub

Sub ACO_Script
	Dim StrAco
	Const ForAppending = 8 
	Start_Aco_Script.Value = ""
	If objFSO.FileExists(strLogFile) Then
		Set objFile = objFSO.OpenTextFile(strLogFile,ForAppending,True)
	Else
		Set objFile = objFSO.CreateTextFile(strLogFile)
	End If
	
	StrAco = objShell.Run("E:\Sources\ACO-SRVS\Script_Cosmos\Deploy_INT_v1.3.bat")
		if StrAco = 0 then
		objFile.WriteLine date & " " & time & " The ACO Script was started by " & UserID
		Start_Aco_Script.Value = date & " " & time & " The ACO Script was started by " & UserID
		End if
	objFile.Close

End Sub

Sub ACO_Script_Finish
	Dim StrAco
	Const ForAppending = 8 
	Finish_Aco_Script.Value = ""
	If objFSO.FileExists(strLogFile) Then
		Set objFile = objFSO.OpenTextFile(strLogFile,ForAppending,True)
	Else
		Set objFile = objFSO.CreateTextFile(strLogFile)
	End If
	
	StrAco = objShell.Run("E:\Sources\ACO-SRVS\Script_Cosmos\Deploy_INT_v1.3.bat")
		if StrAco = 0 then
		objFile.WriteLine date & " " & time & " The ACO Script was Finished correctly by " & UserID
		Finish_Aco_Script.Value = date & " " & time & " The ACO Script was Finished by " & UserID
		End if
	objFile.Close

End Sub


</script>

<body>
<h1 align='center'>Collaboration Service Checklist</h1>
<BODY BGCOLOR="#D4D0C8">
<table border="1">
<tr>
	<td align="center" style="font-family: arial; font-size: 16px; font-weight: bold;">
	Before the Deployment
</td>
		</tr>
	<tr height="100">
		<td>
			<input type="button" value="Check EventViewer" name="backup_sps_button"  onClick="Check_EventVwr">
			
		</td>
		<td width="500">
			<textarea name="Start_chk_bkp" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Check SPS Solutions" name="backup_sps_button"  onClick="Check_SPS_Solutions_Before">
			
		</td>
		<td width="500">
			<textarea name="Check_Solution_Before" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Start ACO Script" name="backup_sps_button"  onClick="ACO_Script">
			
		</td>
		<td width="500">
			<textarea name="Start_ACO_Script" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Backup SPS" name="backup_sps_button"  onClick="BackupSPS">
			
		</td>
		<td width="500">
			<textarea name="BKP_Aco_Script" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Permissions snapshot" name="backup_sps_button"  onClick="ACO_Script_Finish">
			
		</td>
		<td width="500">
			<textarea name="" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			
		</td>
		<td width="500">
		</td>
	</tr>
<tr>
	<td align="center" style="font-family: arial; font-size: 16px; font-weight: bold;">
	After the Deployment
</td>
	<tr height="100">
		<td>
			<input type="button" value="Finish ACO Script" name="backup_sps_button"  onClick="ACO_Script_Finish">
			
		</td>
		<td width="500">
			<textarea name="Finish_Aco_Script" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
</table>
</body>

Open in new window




Thanks in advance,
0
Comment
Question by:Gonzalo Becerra
  • 9
  • 5
  • 2
  • +1
17 Comments
 
LVL 1

Author Comment

by:Gonzalo Becerra
ID: 35483146
Anyone can help me to understand how can I do ?
0
 
LVL 12

Assisted Solution

by:rlandquist
rlandquist earned 200 total points
ID: 35483775
Here is the Body Code that shows how to insert the image.  Save the picture as image1.jpg in the same folder as the hta
<body>
<h1 align='center'>Collaboration Service Checklist</h1>
<BODY BGCOLOR="#D4D0C8">
<table border="1">
<tr>
	<td align="center" style="font-family: arial; font-size: 16px; font-weight: bold;">
	Before the Deployment
</td>

		</tr>
	<tr height="100">
		<td>
			<input type="button" value="Check EventViewer" name="backup_sps_button"  onClick="Check_EventVwr">
			
		</td>
		<td width="500">
			<textarea name="Start_chk_bkp" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
        <td width="500" rowspan="5"><img src="image1.jpg" />
</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Check SPS Solutions" name="backup_sps_button"  onClick="Check_SPS_Solutions_Before">
			
		</td>
		<td width="500">
			<textarea name="Check_Solution_Before" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Start ACO Script" name="backup_sps_button"  onClick="ACO_Script">
			
		</td>
		<td width="500">
			<textarea name="Start_ACO_Script" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Backup SPS" name="backup_sps_button"  onClick="BackupSPS">
			
		</td>
		<td width="500">
			<textarea name="BKP_Aco_Script" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Permissions snapshot" name="backup_sps_button"  onClick="ACO_Script_Finish">
			
		</td>
		<td width="500">
			<textarea name="" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			
		</td>
		<td width="500">
		</td>
	</tr>
<tr>
	<td align="center" style="font-family: arial; font-size: 16px; font-weight: bold;">
	After the Deployment
</td>
	<tr height="100">
		<td>
			<input type="button" value="Finish ACO Script" name="backup_sps_button"  onClick="ACO_Script_Finish">
			
		</td>
		<td width="500">
			<textarea name="Finish_Aco_Script" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
</table>
</body>

Open in new window

0
 
LVL 1

Author Comment

by:Gonzalo Becerra
ID: 35502359
Thanks rlandquist for your help, I would like understand how can I do the step 2 and 3 because I need finish this HTA as soon as possible.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 600 total points
ID: 35509559
Hi there,

Give this a go.  It will load the URL you enter in the URL text box, and return the message box result (of yes or no) to intResponse.

It will also pass the number entered to the script specified in:
                  strVBS = "\\server\share\Sharepoint_Restore.vbs"

You will need to add the script itself, something like
intNumber = WScript.Arguments(0)

to capture that number for use in the script.

Regards,

Rob.
<script language="vbscript">
	Sub Browse_URL
		Set objIE = CreateObject("InternetExplorer.Application")
		objIE.Visible = True
		objIE.Navigate txt_url.Value
		While objIE.Busy Or objIE.ReadyState <> 4
			HTASleep 1
		Wend
		On Error Resume Next
		While Err.Number = 0
			HTASleep 1
			strTitle = objIE.LocationURL
		Wend
		Err.Clear
		intResponse = MsgBox("Did the web page load correctly?", vbYesNo, "Confirmation")
	End Sub
	
	Sub HTASleep(intSeconds)
		Set objShell = CreateObject("WScript.Shell")
		objShell.Run "ping 127.0.0.1 -n " & intSeconds + 1, 0, True
	End Sub
	
	Sub Run_Script
		If txt_sharepoint.Value <> "" Then
			strVBS = "\\server\share\Sharepoint_Restore.vbs"
			Set objFSO = CreateObject("Scripting.FileSystemObject")
			Set objShell = CreateObject("WScript.Shell")
			strCommand = "wscript.exe " & objFSO.GetFile(strVBS).ShortPath & " " & txt_sharepoint.Value
			objShell.Run strCommand, 1, False
			MsgBox "Script is running."
		Else
			MsgBox "Please enter a Sharepoint backup number."
		End If
	End Sub
</script>
<body>
<h1 align='center'>Collaboration Service Checklist</h1>
<BODY BGCOLOR="#D4D0C8">
<table border="1">
	<tr>
		<td align="center" style="font-family: arial; font-size: 16px; font-weight: bold;">
			Before the Deployment
		</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Check EventViewer" name="backup_sps_button"  onClick="Check_EventVwr">
		</td>
		<td width="500">
			<textarea name="Start_chk_bkp" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
		<td width="500" rowspan="5"><img src="image1.jpg" />
		</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Check SPS Solutions" name="backup_sps_button"  onClick="Check_SPS_Solutions_Before">
		</td>
		<td width="500">
			<textarea name="Check_Solution_Before" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Start ACO Script" name="backup_sps_button"  onClick="ACO_Script">
		</td>
		<td width="500">
			<textarea name="Start_ACO_Script" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Backup SPS" name="backup_sps_button"  onClick="BackupSPS">
		</td>
		<td width="500">
			<textarea name="BKP_Aco_Script" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Permissions snapshot" name="backup_sps_button"  onClick="ACO_Script_Finish">
		</td>
		<td width="500">
			<textarea name="" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			&nbsp;
		</td>
		<td width="500">
			&nbsp;
		</td>
	</tr>
	<tr>
		<td align="center" style="font-family: arial; font-size: 16px; font-weight: bold;">
			After the Deployment
		</td>
		<td width="500">
			&nbsp;
		</td>		
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Finish ACO Script" name="backup_sps_button"  onClick="ACO_Script_Finish">
		</td>
		<td width="500">
			<textarea name="Finish_Aco_Script" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="50">
		<td colspan="2">
			URL: <input type="text" id="txt_url" name="txt_url" size="80">
		</td>
		<td width="500">
			<input type="button" value="Browse..." name="btn_browse_url" onClick="Browse_URL">
		</td>
	</tr>
	<tr height="50">
		<td colspan="2">
			Restore Sharepoint Backup number: <input type="text" id="txt_sharepoint" name="txt_sharepoint" size="40">
		</td>
		<td width="500">
			<input type="button" value="Run Script" name="btn_run_script" onClick="Run_Script">
		</td>
	</tr>
</table>
</body>

Open in new window

0
 
LVL 1

Author Comment

by:Gonzalo Becerra
ID: 35509807
Thanks Rob for your help.
1-  I have this error when I close the Internet Explorer after explore the site.
2- To adapt this script I add this line on my script mentioned in my question?

intNumber = WScript.Arguments(0)

 Error

Thanks in advance,
0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 600 total points
ID: 35509915
Hi,

1) You must be using IE8.....in that case, the security model has changed, and automation does not work for the Internet zone.  You will need to change this section:
	Sub Browse_URL
		Set objIE = CreateObject("InternetExplorer.Application")
		objIE.Visible = True
		objIE.Navigate txt_url.Value
		While objIE.Busy Or objIE.ReadyState <> 4
			HTASleep 1
		Wend
		On Error Resume Next
		While Err.Number = 0
			HTASleep 1
			strTitle = objIE.LocationURL
		Wend
		Err.Clear
		intResponse = MsgBox("Did the web page load correctly?", vbYesNo, "Confirmation")
	End Sub

Open in new window


to this:
	Sub Browse_URL
		Set objIE = CreateObject("InternetExplorer.Application")
		objIE.Visible = True
		objIE.Navigate txt_url.Value
		intResponse = MsgBox("Did the web page load correctly?", vbYesNo, "Confirmation")
	End Sub

Open in new window


which will just prompt immediately as the page loads, instead of waiting for it to be closed manually.

2) I assume you want to change this line:
            sBackuptoRestore = Inputbox("Enter the BAK File to Restore: e.g.: E:\Temp\Backups\eForms\WO_444.bak","Enter file Location" ,"")

to become dynamic from the number in the HTA, so do the following:
a) add Dim intNumber to the top somewhere
b) add intNumber = WScript.Arguments(0) just under that line
c) change
            sBackuptoRestore = Inputbox("Enter the BAK File to Restore: e.g.: E:\Temp\Backups\eForms\WO_444.bak","Enter file Location" ,"")
to
            sBackuptoRestore = Inputbox("Enter the BAK File to Restore: e.g.: E:\Temp\Backups\eForms\WO_444.bak","Enter file Location" ,"E:\Temp\Backups\eForms\WO_" & intNumber & ".bak")

Regards,

Rob.
0
 
LVL 1

Author Comment

by:Gonzalo Becerra
ID: 35721346
Dear Rob sorry for the delay I had a Big Issues and I delay with this:

I have this Script (I replaced intNumber by nWO)
Option Explicit
Dim SiteURL, C_SiteURL, sAplic, nWO
nWO = WScript.Arguments(0)
msgbox nWO
'nWO = InputBox("Enter the WO number","e.g.:1001548 (Only the Number)","")
sAplic = InputBox("Application Name","e.g.: MCM-QA","Application-Enviroment")
Const BackupPath = "E:\Temp\Backups\"
SiteURL = Inputbox ("Enter the URL to Backup","e.g.: http://url", "http://")
C_SiteURL = Chr(34) & SiteURL & chr(34)
Const C_NamePrefix = "SharePoint_"
Const C_SharePointBin = "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Bin"

Dim fso, folder, filedate, f, file
Dim sBackupPrefix

Set fso = CreateObject("Scripting.FileSystemObject")

if Not fso.FolderExists(BackupPath) then
WScript.Echo "The folder " & BackupPath & " does not exist!"
WScript.Quit
end if

Set folder = fso.GetFolder(BackupPath)
filedate = now
Set f = Nothing

' Assigns a name of the new file
sBackupPrefix = BackupPath & sAplic & "_" & "WO" & nWO & "_" & year(now) & right("00" & Month(now),2) & right("00" & day(now),2)

Set folder = fso.CreateFolder(sBackupPrefix)

Dim objShell
Dim strcmd
Dim runas
Dim sPwd
Dim sUserName
Dim SPBackupFile
Dim sInetpub
sUserName = Inputbox("Enter the Service Account: e.g. Domain\Service Account","Enter the Service Account", "")
sPwd = Inputbox("Enter the password for: " & sUserName,"Enter the Service Account Password", "")
SPBackupFile = "E:\ACO-Scripts"
sInetpub = Inputbox("Enter the Application Folder: e.g. E:\Inetpub\eforms","Enter the Application Folder", "")
Set objShell = CreateObject("WScript.Shell")


Dim psexec, psexeccmd, objexec
psexec = "E:\ACO-Scripts\psexec.exe"
psexec = fso.getfile(psexec).ShortPath
psexeccmd = psexec & " -accepteula -u " & sUserName & " -p " & sPwd & " \\" & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%") & " cmd /c " 
strcmd = "Powershell -command " & fso.getfolder(SPBackupFile).ShortPath &"\spbackup.ps1 " & fso.getfolder(SPBackupFile) &"\spbackup.xml " & SiteURL & " " & sBackupPrefix & " " &sInetpub
'Inputbox "Running command", "Command", psexeccmd & strcmd
Set objexec = objShell.exec(psexeccmd & strcmd)

While objexec.Status = 0
	WScript.Sleep 100
Wend

WScript.Echo "Backup of site collection successful"
Set objshell = nothing

Open in new window


But for example I did execute: Backup_SPS_PS.vbs 3333 (3333 is the nWO) and I obtain the following error:
Error
0
 
LVL 46

Expert Comment

by:aikimark
ID: 35721548
@gbecerra

I think you probably need to check that there are arguments before you reference them.
Example:
If WScript.Arguments.Count > 0 Then
  nWO = WScript.Arguments(0)
End If

Open in new window


Reference: http://technet.microsoft.com/en-us/library/ee156618.aspx
0
 
LVL 1

Author Comment

by:Gonzalo Becerra
ID: 35722025
@aikimark

Thansk for your help, I don't have more errors but the nWO value is null; if you see in the image I added the msgbox to see the value but is null.


 Null
This is the script now:
 
Option Explicit
Dim SiteURL, C_SiteURL, sAplic, nWO
If WScript.Arguments.Count > 0 Then
  nWO = WScript.Arguments(0)
End If
msgbox nWO
'nWO = InputBox("Enter the WO number","e.g.:1001548 (Only the Number)","")
sAplic = InputBox("Application Name","e.g.: MCM-QA","Application-Enviroment")
Const BackupPath = "E:\Temp\Backups\"
SiteURL = Inputbox ("Enter the URL to Backup","e.g.: http://url", "http://")
C_SiteURL = Chr(34) & SiteURL & chr(34)
Const C_NamePrefix = "SharePoint_"
Const C_SharePointBin = "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Bin"

Dim fso, folder, filedate, f, file
Dim sBackupPrefix

Set fso = CreateObject("Scripting.FileSystemObject")

if Not fso.FolderExists(BackupPath) then
WScript.Echo "The folder " & BackupPath & " does not exist!"
WScript.Quit
end if

Set folder = fso.GetFolder(BackupPath)
filedate = now
Set f = Nothing

' Assigns a name of the new file
sBackupPrefix = BackupPath & sAplic & "_" & "WO" & nWO & "_" & year(now) & right("00" & Month(now),2) & right("00" & day(now),2)

Set folder = fso.CreateFolder(sBackupPrefix)

Dim objShell
Dim strcmd
Dim runas
Dim sPwd
Dim sUserName
Dim SPBackupFile
Dim sInetpub
sUserName = Inputbox("Enter the Service Account: e.g. Domain\Service Account","Enter the Service Account", "")
sPwd = Inputbox("Enter the password for: " & sUserName,"Enter the Service Account Password", "")
SPBackupFile = "E:\ACO-Scripts"
sInetpub = Inputbox("Enter the Application Folder: e.g. E:\Inetpub\eforms","Enter the Application Folder", "")
Set objShell = CreateObject("WScript.Shell")


Dim psexec, psexeccmd, objexec
psexec = "E:\ACO-Scripts\psexec.exe"
psexec = fso.getfile(psexec).ShortPath
psexeccmd = psexec & " -accepteula -u " & sUserName & " -p " & sPwd & " \\" & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%") & " cmd /c " 
strcmd = "Powershell -command " & fso.getfolder(SPBackupFile).ShortPath &"\spbackup.ps1 " & fso.getfolder(SPBackupFile) &"\spbackup.xml " & SiteURL & " " & sBackupPrefix & " " &sInetpub
'Inputbox "Running command", "Command", psexeccmd & strcmd
Set objexec = objShell.exec(psexeccmd & strcmd)

While objexec.Status = 0
	WScript.Sleep 100
Wend

WScript.Echo "Backup of site collection successful"
Set objshell = nothing

Open in new window

0
 
LVL 46

Assisted Solution

by:aikimark
aikimark earned 1200 total points
ID: 35722475
Let's see if there are any recognized arguments.  Please try your code with this diagnostic statement:

msgbox nWO & ": " & WScript.Arguments.Count

Open in new window

0
 
LVL 1

Author Comment

by:Gonzalo Becerra
ID: 35722531
I added that but I have this message:

 Message
0
 
LVL 46

Expert Comment

by:aikimark
ID: 35722591
At least we now know that it isn't recognizing the 43434 argument even exists.  Most curious.
0
 
LVL 1

Author Comment

by:Gonzalo Becerra
ID: 35722662
You think I'm wrong how to call script or any in the script?

This is the code:
 
Option Explicit
Dim SiteURL, C_SiteURL, sAplic, nWO, args
Set args = WScript.Arguments
If WScript.Arguments.Count > 0 Then
  nWO = WScript.Arguments(0)
End If
msgbox nWO & ": " & WScript.Arguments.Count
'nWO = InputBox("Enter the WO number","e.g.:1001548 (Only the Number)","")
sAplic = InputBox("Application Name","e.g.: MCM-QA","Application-Enviroment")
Const BackupPath = "E:\Temp\Backups\"
SiteURL = Inputbox ("Enter the URL to Backup","e.g.: http://url", "http://")
C_SiteURL = Chr(34) & SiteURL & chr(34)
Const C_NamePrefix = "SharePoint_"
Const C_SharePointBin = "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Bin"

Dim fso, folder, filedate, f, file
Dim sBackupPrefix

Set fso = CreateObject("Scripting.FileSystemObject")

if Not fso.FolderExists(BackupPath) then
WScript.Echo "The folder " & BackupPath & " does not exist!"
WScript.Quit
end if

Set folder = fso.GetFolder(BackupPath)
filedate = now
Set f = Nothing

' Assigns a name of the new file
sBackupPrefix = BackupPath & sAplic & "_" & "WO" & nWO & "_" & year(now) & right("00" & Month(now),2) & right("00" & day(now),2)

Set folder = fso.CreateFolder(sBackupPrefix)

Dim objShell
Dim strcmd
Dim runas
Dim sPwd
Dim sUserName
Dim SPBackupFile
Dim sInetpub
sUserName = Inputbox("Enter the Service Account: e.g. Domain\Service Account","Enter the Service Account", "")
sPwd = Inputbox("Enter the password for: " & sUserName,"Enter the Service Account Password", "")
SPBackupFile = "E:\ACO-Scripts"
sInetpub = Inputbox("Enter the Application Folder: e.g. E:\Inetpub\eforms","Enter the Application Folder", "")
Set objShell = CreateObject("WScript.Shell")


Dim psexec, psexeccmd, objexec
psexec = "E:\ACO-Scripts\psexec.exe"
psexec = fso.getfile(psexec).ShortPath
psexeccmd = psexec & " -accepteula -u " & sUserName & " -p " & sPwd & " \\" & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%") & " cmd /c " 
strcmd = "Powershell -command " & fso.getfolder(SPBackupFile).ShortPath &"\spbackup.ps1 " & fso.getfolder(SPBackupFile) &"\spbackup.xml " & SiteURL & " " & sBackupPrefix & " " &sInetpub
'Inputbox "Running command", "Command", psexeccmd & strcmd
Set objexec = objShell.exec(psexeccmd & strcmd)

While objexec.Status = 0
	WScript.Sleep 100
Wend

WScript.Echo "Backup of site collection successful"
Set objshell = nothing

Open in new window

0
 
LVL 46

Accepted Solution

by:
aikimark earned 1200 total points
ID: 35722777
I pasted the first few lines of your script into a  .VBS file on my PC and ran it with an argument and without an argument and it recognized that it had an argument and that argument's value in the first test.  It recognized that there was no argument in the second test.  I invoked my script the same way you did (by name from a command line).  I did not use Cscript or Wscript to invoke the script.

That is one of the reasons that makes this so curious...it works on my system.

=====
Although I doubt it will make any difference, please try this:
msgbox WScript.Arguments.Item(0) & " : " & WScript.Arguments.Count

Open in new window

0
 
LVL 1

Author Comment

by:Gonzalo Becerra
ID: 35722874
Cool it's Works Thanks A lot!! :D
0
 
LVL 1

Author Closing Comment

by:Gonzalo Becerra
ID: 35722918
Excellent, thanks for all
0
 
LVL 46

Expert Comment

by:aikimark
ID: 35722919
I don't understand how you can have zero arguments, but have an arguments.items(0) value.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
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…
Introduction to Processes
Suggested Courses

621 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