Login | |
|
 |
IF statement within a IF statement, possible? - 9/23/2005 9:00:11 AM
|
|
 |
|
| |
kracksmith
Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
|
Is it possible to implement a IF statement within a IF statement?? I've tried to search this out but found nothing about 2 IF statement within. What I'm trying to do is if "c:\Program Files\DataCAD\DataCAD.11.08.01.exe" exist then quit. If not then copy and run. I'm putting this in my login script and if the user already ran it once I don't want them to run it again if they accidentally logged off at lunch time. Option Explicit Dim network, fso, WshShell Set network = CreateObject("WScript.Network") Set fso = CreateObject("Scripting.FileSystemObject") Set WshShell = Wscript.CreateObject("Wscript.Shell") Const datacad_group = "datacad" If isMemberOf(datacad_group) Then fso.CopyFile "\\Prod2\J_Drive\Revision\Update\DCAD11\DataCAD.11.08.01.exe", "C:\Program Files\DataCAD\" WScript.Sleep 4000 WshShell.run "cmd /c ""c:\Program Files\DataCAD\DataCAD.11.08.01.exe""",0,True WScript.Echo "DataCAD update version 8 has been installed, Thank you" end IF Function isMemberOf(ByVal group) Dim user, found, temp found = False Set user = GetObject("WinNT://" & CreateObject("WScript.Network").UserDomain & "/" & CreateObject("WScript.Network").UserName & ",user") For Each temp In user.Groups If UCase(temp.Name) = UCase(group) Then found = True Exit For End If Next isMemberOf = found End Function
|
|
| |
|
|
|
 |
RE: IF statement within a IF statement, possible? - 9/23/2005 5:02:19 PM
|
|
 |
|
| |
Snipah
Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
|
If FSO.FileExists("c:\Program Files\DataCAD\DataCAD.11.08.01.exe") Then ' MsgBox "File Found" Wscript.Quit(0) Else fso.CopyFile "\\Prod2\J_Drive\Revision\Update\DCAD11\DataCAD.11.08.01.exe", "C:\Program Files\DataCAD\" WScript.Sleep 4000 WshShell.run "cmd /c ""c:\Program Files\DataCAD\DataCAD.11.08.01.exe""",0,True WScript.Echo "DataCAD update version 8 has been installed, Thank you" End If Else is easier to use, but you can always nest If's (if needed, else not ), only in you case Else is more suitable. Snipah
< Message edited by Snipah -- 9/23/2005 5:03:42 PM >
_____________________________
For more information, please see the "Read me First" topic. http://www.visualbasicscript.com
|
|
| |
|
|
|
 |
RE: IF statement within a IF statement, possible? - 9/24/2005 6:44:20 AM
|
|
 |
|
| |
Snipah
Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
|
quote:
so if I use your sugguestion I would need to create a nested IF statement. See below: If isMemberOf(datacad_group) Then ' when the use is a member If FSO.FileExists("c:\Program Files\DataCAD\DataCAD.11.08.01.exe") Then ' find the file ' MsgBox "File Found" Wscript.Quit(0) Else ' or if not found... fso.CopyFile "\\Prod2\J_Drive\Revision\Update\DCAD11\DataCAD.11.08.01.exe", "C:\Program Files\DataCAD\" WScript.Sleep 4000 WshShell.run "cmd /c ""c:\Program Files\DataCAD\DataCAD.11.08.01.exe""",0,True WScript.Echo "DataCAD update version 8 has been installed, Thank you" End If Else ' if the user is not a member MsgBox "You are not a member..." End If
< Message edited by Snipah -- 9/24/2005 6:46:31 AM >
_____________________________
For more information, please see the "Read me First" topic. http://www.visualbasicscript.com
|
|
| |
|
|
|
 |
RE: IF statement within a IF statement, possible? - 9/26/2005 4:59:36 PM
|
|
 |
|
| |
Snipah
Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
|
on our site we have several topics where RunAs is covered, please do a Search.. S
_____________________________
For more information, please see the "Read me First" topic. http://www.visualbasicscript.com
|
|
| |
|
|
|
 |
RE: IF statement within a IF statement, possible? - 9/27/2005 3:14:35 AM
|
|
 |
|
| |
ebgreen
Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
|
quote:
ORIGINAL: kracksmith but this won't run and everything looks right. C Could you expound please?
|
|
| |
|
|
|
 |
RE: IF statement within a IF statement, possible? - 9/27/2005 3:33:26 AM
|
|
 |
|
| |
kracksmith
Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
|
expound?? What do you mean? Here is my entire script if that is what you meant. Option Explicit on error resume next Dim network, fso, WshShell Set network = CreateObject("WScript.Network") Set fso = CreateObject("Scripting.FileSystemObject") Set WshShell = Wscript.CreateObject("Wscript.Shell") Const datacad_group = "datacad" If isMemberOf(datacad_group) Then If FSO.FileExists("c:\Program Files\DataCAD\DataCAD.11.08.01.exe") Then 'just go to the next line' Wscript.Quit(0) Else fso.CopyFile "\\Prod2\J_Drive\Revision\Update\DCAD11\DataCAD.11.08.01.exe", "C:\Program Files\DataCAD\" WScript.Sleep 4000 WshShell.run "cmd /k runas /user:admin ""c:\Program Files\DataCAD\DataCAD.11.08.01.exe""",0,True WScript.Sleep 100 WshShell.Sendkeys "xxxx" WScript.Echo "DataCAD update version 8 has been installed, Thank you" End If Else End If Function isMemberOf(ByVal group) Dim user, found, temp found = False Set user = GetObject("WinNT://" & CreateObject("WScript.Network").UserDomain & "/" & CreateObject("WScript.Network").UserName & ",user") For Each temp In user.Groups If UCase(temp.Name) = UCase(group) Then found = True Exit For End If Next isMemberOf = found End Function
|
|
| |
|
|
|
 |
RE: IF statement within a IF statement, possible? - 9/27/2005 3:45:40 AM
|
|
 |
|
| |
ebgreen
Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
|
I meant what do you mean by "but this won't run"? Is there an error? does nothing happen at all? Does part of the script work then it just stops? If there is an error, what is the error? If there is an error, what line does it error on? If there is no error, have you tried removing On Error Resume Next to see if there is an error that is being masked by it?
|
|
| |
|
|
|
 |
RE: IF statement within a IF statement, possible? - 9/27/2005 4:57:55 AM
|
|
 |
|
| |
Snipah
Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
|
Where is your Else statement? To make it easier to follow where the script is at running time, make the following changes: If isMemberOf(datacad_group) Then If FSO.FileExists("c:\Program Files\DataCAD\DataCAD.11.08.01.exe") Then 'just go to the next line Msgbox "Found file AND you are a DataCAD group-member" Wscript.Quit(0) Else MsgBox "File not found BUT you are a DataCAD group-member" fso.CopyFile "\\Prod2\J_Drive\Revision\Update\DCAD11\DataCAD.11.08.01.exe", "C:\Program Files\DataCAD\" WScript.Sleep 4000 WshShell.run "cmd /k runas /user:admin ""c:\Program Files\DataCAD\DataCAD.11.08.01.exe""",0,True WScript.Sleep 100 WshShell.Sendkeys "xxxx" WScript.Echo "DataCAD update version 8 has been installed, Thank you" End If Else MsgBox "Didn't even look for the file BECAUSE you are not a DataCAD group-member" End If
_____________________________
For more information, please see the "Read me First" topic. http://www.visualbasicscript.com
|
|
| |
|
|
|
 |
RE: IF statement within a IF statement, possible? - 9/27/2005 5:58:03 AM
|
|
 |
|
| |
Snipah
Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
|
issues like these are usually minor things, but just like when building a plane...it is not good to have some loose screws... You must supply an [RETURN] command after the xxxx WshShell.run "cmd /k runas /user:admin ""c:\Program Files\DataCAD\DataCAD.11.08.01.exe""",0,True WScript.Sleep 100 WshShell.Sendkeys "xxxx~" The [RETURN] command is ~ or {ENTER} // edit: i should've seen it earlier, my bad....
< Message edited by Snipah -- 9/27/2005 5:59:21 AM >
_____________________________
For more information, please see the "Read me First" topic. http://www.visualbasicscript.com
|
|
| |
|
|
|
 |
RE: IF statement within a IF statement, possible? - 9/27/2005 6:55:39 AM
|
|
 |
|
| |
Snipah
Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
|
Do you actually have a user called ADMIN? better refer to Administrator.... Else It's a cheap escape for now, but try this third party app: http://www.quimeras.com/Products/displayproduct.asp?IdProduct=4 TqcRunas provides the following advantages: - TqcRunas builds a strongly encrypted file that stores all your specifications to runas a command and to control the process created. Thus you can exactly specify with programs and options your users can run with administrator's privileges without reveal the administrator's password.
- TqcRunas can improve its security by use of digital certificates to encrypt the TqcRunas settings.
- You can make use of TqcRunas advantages using the executable module directly or using the provided ActiveX objects.
- TqcRunas can be easily distributed to your clients computers or they can use them directly from a network share.
< Message edited by Snipah -- 9/27/2005 6:59:29 AM >
_____________________________
For more information, please see the "Read me First" topic. http://www.visualbasicscript.com
|
|
| |
|
|
|
 |
RE: IF statement within a IF statement, possible? - 9/27/2005 8:02:37 AM
|
|
 |
|
| |
Snipah
Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
|
Theses are the options for the intWindowStyle from the Run-box WshShell.Run strCommand [,intWindowStyle] [,bWaitOnReturn] 0 Hides the window and activates another window. 1 Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time. 2 Activates the window and displays it as a minimized window. 3 Activates the window and displays it as a maximized window. 4 Displays a window in its most recent size and position. The active window remains active. 5 Activates the window and displays it in its current size and position. 6 Minimizes the specified window and activates the next top-level window in the Z order. 7 Displays the window as a minimized window. The active window remains active. 8 Displays the window in its current state. The active window remains active. 9 Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window. 10 Sets the show state based on the state of the program that started the application
_____________________________
For more information, please see the "Read me First" topic. http://www.visualbasicscript.com
|
|
| |
|
|
|
|
|