Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Permission denied error while running script 1

Status
Not open for further replies.

sglab

Technical User
Jul 29, 2003
104
US
Hello everyone,

I hope someone could give an advice here. I'm trying to figure out how to run scripts remotely - so, I started slowly with a simplest script, which I can't seem get to work.
Code:
Dim Controller, RemoteScript
Set Controller = WScript.CreateObject("WSHController")
WScript.Echo("Connecting...")
Set RemoteScript = Controller.CreateScript("test_3.vbs", "\\H11929")
WScript.Echo("Executing...")
WScript.ConnectObject RemoteScript, "remote_"
RemoteScript.Execute

"test_3.vbs" script is just supposed to display version of Script Host.

Whenever I run this script I get "permission denied" error at the line with "CreateScript" method. I have admin rights on both host and server machines.

Any help would be greatly appreciated.

Best regards.
 
Have you updated the registries on the remote systems to be able to run scripts remotely??



Example from MS TechNET - WshController Object
Code:
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "RemoteComputerName"

Set objRegProv = GetObject("winmgmts:{impersonationLevel=Impersonate}" & _
 "!\\" & strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\Microsoft\Windows Script Host\Settings"
objRegProv.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,"Remote","1"

Hope this helps

Thanks

John Fuhrman
faq329-6766
faq329-7301
thread329-1334328
thread329-1424438
 
Hello John,

sorry for late response - after couple of days I kinda have given up on waiting for help. The answer to your question would be 'yes'. Turned out that doing just that is not enough: one has to change DCOM configuration for WSHost for it to work. So now I'm not getting "Permission deined" errors and I'm able to, say, create file and copy it to remote machine. But that's just for practicing purposes. Here's what I really need to accomplish: for production needs I want to be able to change TimeZone settings on several network machines at once instead of going to each one of them through VNC and doing it manually. We already have a script - somebody wrote it - that changes TimeZone and Desktop wallpaper image to match selected TimeZone. It works fine when it's run locally on each machine, but when I try to use remote scripting, this doesn't do anything. I can only see wscript.exe running in Task Manager, but that's it.
Will you be so kind and take a look at the script I'm trying to run.
Please reply and I'll post a code.

Thank you in advance.
 
Wht not have the script check the TZ settings on the PC it is running on and if not what is expected then change it. This way it could be deployed through a system logon script?

If you can post the code with some comments everyone here can then take a look and possibly come up with a solution.



Thanks

John Fuhrman
faq329-6766
faq329-7301
thread329-1334328
thread329-1424438
 
Hello John,

thanks for your reply. Actually, I have found quite a few scripts on the Internet, that do work. And I think I have figured out why script we're using is not working the way it should. Below is the sample code that works fine when it's executed locally - it changes TZ to Central Standard Time and wallpaper to "LAW_Central_Standard_Time.jpg":

Code:
' Create the variables needed
Dim WSHShell
Dim WSHApp
Dim strRegKey
Dim strWallpaper
Dim strOSRoot
Dim strDesktop
Dim strDisplayProp
Dim strDateAndTimeProperties

' Create the Wscript Shell object
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set WSHApp   = CreateObject("Shell.Application")

' Define the wallpaper
strWallpaper   = "C:\LAW_Timezone_Changer\LAW_Wallpapers\LAW_Central_Standard_Time.jpg"
strDesktop     = WSHShell.SpecialFolders("Desktop")
strDisplayProp = "Display Properties"
strDateAndTimeProperties = "Date and Time Properties"

' Create the wallpaper key
strRegKey =  "HKCU\Control Panel\Desktop\Wallpaper"

' Modified for daylight saving
WSHShell.Run "control.exe timedate.cpl,,/z Central Standard Time" ,0 ,false
Wscript.Sleep 1000
WSHShell.Run "control.exe timedate.cpl,,/z"
Do Until WSHShell.AppActivate (strDateAndTimeProperties)
Loop
WSHShell.SendKeys "{TAB} {TAB}~"

' Write the key, type, and value
WSHShell.RegWrite strRegKey, strWallpaper, "REG_SZ"

' Refresh the desktop now.
WSHApp.ControlPanelItem cstr("desk.cpl")
Do Until WSHShell.AppActivate (strDisplayProp)
Loop
WSHShell.SendKeys "{down}{up}{tab 3}a~"

Main idea was to write a little script, that would copy script above to the remote machine and execute it there. Obviously, it doesn't work and my guess would be that since script uses AppActivate, it gets stuck in endless loop, because Date and Time Properties window just doesn't show up and hence, doesn't get focus for SendKeys method to work. And it even doesn't get to Display Properties window. I guess, the only good thing about this script is that it refreshes desktop wallpaper right away.

So, what's your opinion?

Thank you.
 
You are correct in your thinking. What I would do is not use send keys for this. I would modify the registry areas to set the TZ information needed. This is much quicker and does not require screen manipulations.


Here is an example from VBSedit

Code:
' Set the Time Zone Offset from Greenwich Mean Time



On Error Resume Next

strComputer = "."
'Change value to reflect desired GMT offset in minutes.
intGMTOffset = -480

Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colCompSys = objWMIService.ExecQuery _
 ("Select * from Win32_ComputerSystem")

For Each objCompSys in colCompSys
  objCompSys.CurrentTimeZone = intGMTOffset
  objCompSys.Put_
  If Err = 0 Then
    Wscript.Echo "Time zone set to specified value."
  Else
    Wscript.Echo "Unable to set time zone."
  End If
  Err.Clear
Next

Hope this helps.

Thanks

John Fuhrman
faq329-6766
faq329-7301
thread329-1334328
thread329-1424438
 
Thanks, John.

I have downloaded and installed VbsEdit thing and tried exactly the sample you posted. It works just fine, but there's one thing that looks strange to me. While I can see time change in the System Tray, when I open "Date and Time Properties" dialog I don't see changes there. Why is that?

As far as screen manipulation - changing wallpaper image -, that was mostly to notify user about current TimeZone settings on a particular machine. Not exactly all that necessary, but nice to have.

Best regards.
 
Not sure why the time/date user UI wouldn't show the change.

Your Wallpaper change was being done via registry updates as well. Just add that portion back in.



Thanks

John Fuhrman
faq329-6766
faq329-7301
thread329-1334328
thread329-1424438
 
Thanks, John.

Will do.
Looks like I'm getting closer to accomplishing this task.

Thanks a lot for all your help.

Have a great day.
 
You're welcome. Let me know if you need anything else.

Thanks

John Fuhrman
faq329-6766
faq329-7301
thread329-1334328
thread329-1424438
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top