Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


IF statement within a IF statement, possible?

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,26265
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> IF statement within a IF statement, possible?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 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
 
 
Post #: 1
 
 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

(in reply to kracksmith)
 
 
Post #: 2
 
 RE: IF statement within a IF statement, possible? - 9/23/2005 8:06:01 PM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
so if I use your sugguestion I would need to create a nested IF statement. How do I create a nested IF statement?

I don't think i can do this right?


If isMemberOf(datacad_group) Then

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

(in reply to Snipah)
 
 
Post #: 3
 
 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

(in reply to kracksmith)
 
 
Post #: 4
 
 RE: IF statement within a IF statement, possible? - 9/26/2005 10:23:43 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
thanks for the IF statement.

One small last request before I finish this


Everything is working as accordingly but I need admin rights to install the .exe

All workstation have power users rights.

This .exe can be installed with power users rights but since it's a power user it will be prompted with a

"uninstaller setup failed to initialze. you may not be able to uninstall this product"

so if some how i can install this on their system with admin rights would be very helpful.



(in reply to Snipah)
 
 
Post #: 5
 
 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

(in reply to kracksmith)
 
 
Post #: 6
 
 RE: IF statement within a IF statement, possible? - 9/27/2005 2:50:44 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
ok i did a search like you said and I think i found something. but this won't run and everything looks right. Can you tell me if there is anything wrong?


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 "xxxxxx"
WScript.Echo "DataCAD update version 8 has been installed, Thank you"
End If

(in reply to Snipah)
 
 
Post #: 7
 
 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?

(in reply to kracksmith)
 
 
Post #: 8
 
 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

(in reply to ebgreen)
 
 
Post #: 9
 
 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?

(in reply to kracksmith)
 
 
Post #: 10
 
 RE: IF statement within a IF statement, possible? - 9/27/2005 4:16:36 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
oh sorry, i didn't quite know what you meant.

ok i masked the error and when i run it nothing.

it copies over but not run it with no error remarks.



(in reply to ebgreen)
 
 
Post #: 11
 
 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

(in reply to kracksmith)
 
 
Post #: 12
 
 RE: IF statement within a IF statement, possible? - 9/27/2005 5:18:18 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
Snipah, thanks for all your time but I'm still having trouble running this script.

My Else statement are in there but I just didn't have a "Msgbox"

I did what your script says but still it only copies and not run it.

after i double clicked it, it will copy it over, then a msg will say "File not found BUT you are a DataCAD group-member"
 
then nothing, no errors message or anything i can research it on.
 
waiting "4000" should be that long. but i waited for about 5 minutes and nothing. it just some how stops there.
 
 
 
WshShell.run "cmd /c ""c:\Program Files\DataCAD11\DataCAD.11.08.01.exe""",0,True  'This runs perfect but I need admin rights when running it.

WshShell.run "cmd /k runas /user:admin ""c:\Program Files\DataCAD\DataCAD.11.08.01.exe""",0,True  'This looks right but some how it's not running.



anything minor I'm missing?



(in reply to Snipah)
 
 
Post #: 13
 
 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

(in reply to kracksmith)
 
 
Post #: 14
 
 RE: IF statement within a IF statement, possible? - 9/27/2005 6:45:34 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
Snipah, the return key makes sense. I should have seen that too.

But after inputing "WshShell.Sendkeys "xxx{ENTER}"  or "WshShell.Sendkeys "xxx~"


it still copies but doesnt run the .exe with admin rights being a power user.

this runAS admin, can it be a domain admin or local admin?

I have a local admin and domain admin in the XP client.

Anything else I over looked?

(in reply to Snipah)
 
 
Post #: 15
 
 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

(in reply to kracksmith)
 
 
Post #: 16
 
 RE: IF statement within a IF statement, possible? - 9/27/2005 7:25:51 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
OK I finally got it to run when I removed the CMD /k. but once i got it to run it prompts me the admin password. no matter how long of a time-limit i enter it won't Send Keys the password. the weird part is when it prompts me to enter the admin password it's in a CMD window. i already removed the  CMD from my script though.

I believe once it can send key the password it will run the .exe.

yes i have a user called "admin" and "administrator"

WshShell.run "runas /user:admin ""c:\Program Files\DataCAD\DataCAD.11.08.01.exe"""
WScript.Sleep 4000
WshShell.Sendkeys "XXX{ENTER}" 
WScript.Echo "DataCAD update version 8 has been installed, Thank you"
End If



ok let me check out the link you have for me.

(in reply to Snipah)
 
 
Post #: 17
 
 RE: IF statement within a IF statement, possible? - 9/27/2005 7:44:54 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
ok the reason why It wasn't entering the password on the CMD screen was that specific machine had a different local admin password.

This is working:

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 500
WshShell.run "runas /user:admin ""c:\Program Files\DataCAD\DataCAD.11.08.01.exe"""
WScript.Sleep 500
WshShell.Sendkeys "XXX{ENTER}"
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


This should be my last question. It prompts a CMD screen for the admin password, where in the script do I enter the "0" so the CMD windows don't prompt. That should be it.

< Message edited by kracksmith -- 9/27/2005 8:47:52 AM >

(in reply to kracksmith)
 
 
Post #: 18
 
 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

(in reply to kracksmith)
 
 
Post #: 19
 
 RE: IF statement within a IF statement, possible? - 9/27/2005 9:17:36 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
I put that statement at the end of me .exe.

What syntax am I supposed to use? I always want to use the "0" to hide that cmd window.


Also management is concern about the password.


anyway I can encrypt it in my script? or would I need to purchase a program to conver it over to .exe?

(in reply to Snipah)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> IF statement within a IF statement, possible? Page: [1] 2   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts