Hi Shay,
Thanks for the reply.
First off, all I need to do now is sendkey a "y" for yes and "enter".
I am new to scripting so I may be doing something wrong but I cannot get
this to work even with your code. I am going to try it on a non-vista
machine just in case that's an issue. When I open cmd on my computer, it
says this exactly: Administrator: C:\Windows\System32\cmd.exe
So I modified my script exactly like your changing the above to:
If ($shell.AppActivate("c:\windows\system32"))
If ($shell.AppActivate("c:\windows\system32\"))
If ($shell.AppActivate("c:\windows\system32\cmd.exe"))
If ($shell.AppActivate("administrator c:\windows\system32\cmd.exe"))
But none worked. Here is my exact code with how I believe it should work.
$shell = new-object –com wscript.shell
[void] $shell.Run("cmd")
Start-sleep 2
If ($shell.AppActivate("C:\Windows\System32"))
{
Start-sleep 2
$shell.SendKeys("dir~")
Start-sleep 2
$shell.SendKeys("y~")
Start-sleep 2
$shell.SendKeys("exit~")
#$shell.SendKeys("%{F4}")
}
Thanks,
"Shay Levi" wrote:
>
> Hi
>
> FIGURE2 doesn't work because the AppActivate methos expects the cmd window
> title. On my machine it's
> invoked with the path of system32 in the title. Updating the AppActivate
> argument runs the script without a problem.
> You can also unify some keystrokes:
>
>
> $shell = new-object –com wscript.shell
> [void] $shell.Run("cmd")
> Start-sleep 1
>
> If ($shell.AppActivate("c:\windows\system32"))
> {
> Start-sleep 1
> $shell.SendKeys("del c:\scripts\temp\*.*~")
>
> Start-sleep 1
> $shell.SendKeys("y~")
>
> Start-sleep 1
> $shell.SendKeys("exit~")
> }
>
>
> Keep in mind that this is not a secure method, it'll most likely fail most
> of he time due to the delete operation time length and the sleep intervals.
> Why don't you delete the files with remove-item:
>
> dir c:\scripts\temp\*.* | remove-item -force
>
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
> > I can pass text to calc or notepad, but the same is not true for cmd
> > or winword i.e. FIGURE1(calc) works perfect. FIGURE2(cmd) is a no go.
> > Well it does at least open a command window or winword but will pass
> > NO text…
> >
> > If you have a moment – Thanks.
> >
> > FUGURE1
> > Shell = newobject –com WScript.Shell
> > [void] $shell.Run(“calc”)
> > Start-sleep 1
> > If ($shell.AppActivate(“Calculator”))
> > {
> > “Calculator activated…”
> > Start-sleep 1
> > $shell.SendKeys(“10{+}”)
> > Start-sleep 1
> > $shell.SendKeys(“15”)
> > Start-sleep 1
> > $shell.SendKeys(“~”)
> > Start-sleep 1
> > $shell.SendKeys(“%F4”)
> > }
> > FIGURE2
> > Shell = newobject –com WScript.Shell
> > [void] $shell.Run(“cmd”)
> > Start-sleep 1
> > If ($shell.AppActivate(“cmd”))
> > {
> > “cmd activated…”
> > Start-sleep 1
> > $shell.SendKeys(“delete c:\temp\jess\*.*”)
> > Start-sleep 1
> > $shell.SendKeys(“~”)
> > Start-sleep 1
> > $shell.SendKeys(“y”)
> > Start-sleep
> > $shell.SendKeys(“~”)
> > Start-sleep 1
> > $shell.SendKeys(“exit”)
> > } >
>
>