UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
2 Pages V < 1 2  (Go to first unread post)
   Reply to this topicStart new topic
> Run Powershell From Vbscript    
 
   
EssKayKay
post Feb 24 2020, 02:44 PM
Post#21



Posts: 523
Joined: 5-April 03
From: NE Wisconsin


Ahhh David.....

I think we (read You) got it. There were a couple small issues but all appears to be working as planned. If I notice any other problems I will let you know but for now it works great. I thank you very much for your kind assistance. It truly is appreciated.

Steve
Go to the top of the page
 
EssKayKay
post Feb 24 2020, 04:42 PM
Post#22



Posts: 523
Joined: 5-April 03
From: NE Wisconsin


There is one small item I was wondering about. Is it possible to suppress the Windows Powershell screen from momentarily displaying when a PS routine is called? It flashes after each menu button press. I tried to attach a brief screen shot video showing what happens (PS screen is blue) but didn't work (not sure if videos are allowed). This is no biggie, just wondering.

Thanks,
SKK



Go to the top of the page
 
cheekybuddha
post Feb 24 2020, 05:23 PM
Post#23


UtterAccess Moderator
Posts: 12,620
Joined: 6-December 03
From: Telegraph Hill


Brilliant, Steve! I'm glad you got it working.

Perhaps, if you get a chance (and it doesn't contain anything sensitive), post your final solution here - it may well help others in the future, especially the Powershell code.

thumbup.gif

d

--------------------


Regards,

David Marten
Go to the top of the page
 
EssKayKay
post Feb 24 2020, 08:36 PM
Post#24



Posts: 523
Joined: 5-April 03
From: NE Wisconsin


Here's is my final code:

CODE
' Program to Backup all files
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Set objFso = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")

strShell = "powershell -command " & Chr(34) & " & { $x = New-Object -ComObject Shell.Application; $x.MinimizeAll() }" & Chr(34)
WshShell.Run strShell

X1=Msgbox(" All open programs will be" & vbNewLine & " closed prior to backup. . ." & vbNewLine & "" & vbNewLine & _
" Do you wish to continue?",4, " ~~ BACKUP ~~")

If X1=6 then
  strFolder = "Z:\Backup\"
  Set objFso = CreateObject("Scripting.FileSystemObject")
  If objFso.FolderExists(strFolder) then
    Set WshShell = WScript.CreateObject("WScript.Shell")
    runCmd = "c:\tools\closeAll\CloseALL.exe"
    WshShell.Run "cmd /c " & runCmd, 0, True
    runCmd = "c:\tools\back4sure\back4sure.exe -b -c -q -x c:\tools\back4sure\Backup.b4j"
    WshShell.Run "cmd /c " & runCmd, 0, True
    runCmd = "del Z:\backup\*.log"
    WshShell.Run "cmd /c " & runCmd, 0, True
    Msgbox " BACKUP COMPLETE" & vbNewLine & " _______________________________"
  Else
    X2=Msgbox (" Missing Backup Folder " & vbNewLine & " ~~~~~~~~~~~~~~~~~~~" & vbNewLine & _
    "" & vbNewLine & " Backup folder not available." & vbNewLine & " Verify external drive is connected" _
    & vbNewLine & " and Rerun BACKUP program . . . ." & vbNewLine & "",0, " - OOPS -")
    strShell = "powershell -command " & Chr(34) & " & { $x = New-Object -ComObject Shell.Application; $x.UndoMinimizeAll() }" & Chr(34)
    WshShell.Run strShell
    If X2=4 then
      MsgBox " Backup program will close" & vbNewLine & " Connect external drive and rerun Backup. . . ."
    End If
  End If
  Set objFso = Nothing
  wscript.quit
Else
  IF X1=7 then
    Set WshShell = WScript.CreateObject("WScript.Shell")
    strShell = "powershell -command " & Chr(34) & " & { $x = New-Object -ComObject Shell.Application; $x.UndoMinimizeAll() }" & Chr(34)
    WshShell.Run strShell
    wscript.quit
  End If
End If

This post has been edited by cheekybuddha: Feb 25 2020, 04:35 AM
Go to the top of the page
 
cheekybuddha
post Feb 25 2020, 04:38 AM
Post#25


UtterAccess Moderator
Posts: 12,620
Joined: 6-December 03
From: Telegraph Hill


I hope you don't mind - I edited your code to use code tags to make it more readable.

Thanks for posting your solution

(I still think you can lose the extra calls to Set objFso and WshShell - you've done it at te beginning of the script and they will be available all the way through. Also I think your wscript.quit calls are un-needed - the script will terminate by itself as it runs through)

thumbup.gif

d

--------------------


Regards,

David Marten
Go to the top of the page
 
cheekybuddha
post Feb 25 2020, 04:49 AM
Post#26


UtterAccess Moderator
Posts: 12,620
Joined: 6-December 03
From: Telegraph Hill


Via PM:
QUOTE
However, I do have one other question. When a message button is clicked and a Powershell code line is run there is a blue Windows Powershell screen that briefly appears. Is it possible to suppress this screen?


See here if it helps

It looks like on the PowerShell lines you can use:
CODE
  WshShell.Run strShell, 0


hth,

d

--------------------


Regards,

David Marten
Go to the top of the page
 
EssKayKay
post Feb 25 2020, 10:04 AM
Post#27



Posts: 523
Joined: 5-April 03
From: NE Wisconsin


Perfect! This is exactly what I had in mind.
Thank you very much David. You truly are a man to be admired.

With gratitude,
Steve

Go to the top of the page
 
cheekybuddha
post Feb 25 2020, 05:46 PM
Post#28


UtterAccess Moderator
Posts: 12,620
Joined: 6-December 03
From: Telegraph Hill


yw.gif

--------------------


Regards,

David Marten
Go to the top of the page
 
2 Pages V < 1 2


Custom Search


RSSSearch   Top   Lo-Fi    3rd April 2020 - 02:59 AM