Sign in to follow this  
Followers 0
PKDucky

Opening Folders

23 posts in this topic

Good day,

I am having an issue opening a folder. I tried several ways to get AutoIT to open C:\Windows\System32\oobeInfoBackgrounds without success, so I thought I would try the batch file method. Its running on a Windows 7 system.

I have this line in my script

@ScriptDir run ("open folder.bat")

'open folder.bat' conisist of this line

start "" "C:\Windows\System32\oobeInfoBackgrounds"

Running the batch file opens the folder without issue. However, when AutoIT launches the bat, I get this error:

'Windows cannot find 'C:\Windows\System32\oobeInfoBackgrounds'. Make sure you typed the name correctly, and then try again.

The script is setup to copy background files to my desktop and then ideally to the Backgrounds folder. Since I couldnt get this to work, I am trying get the folder to open so I can drag and drop from my desktop.

Thanks for the assist!

Share this post


Link to post
Share on other sites



If you're just copying files, why do you need it to open Windows Explorer to the folder?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Ill be changing the background each time I update the image. The script reads a file on the target drive to determine the background to use, copies the background to the desktop - renaming in the process, and then replaces the existing files.

If it was just a one time even, the script would be overkill. But since its going to be a monthly event on several images, I thought I would make life easier - or so I thought.

Share this post


Link to post
Share on other sites

That doesn't actually explain what I asked, why are you opening Windows Explorer to do a simple filecopy process? Why do you need a visual representation of the files to do that?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Because I wasnt able to get AutoIT to copy the files to the folder directly. Having Windows Explorer open the folder is a work around.

Share this post


Link to post
Share on other sites

I now have a batch file that succeeded where AutoIT failed.

Share this post


Link to post
Share on other sites

Try adding a #requireadmin to the top of your script, and then reattempt the filecopy


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Here is the entire code, hopefully it will shed some light to what I am trying to do. And I have already tried '#requireadmin'  :)

 

#NoTrayIcon
#include <FileConstants.au3>
#include <Constants.au3>
#include <StringConstants.au3>
#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <ListBoxConstants.au3>
#include <ButtonConstants.au3>
#include <WinAPIFiles.au3>
#include <file.au3>
#RequireAdmin
#AutoIt3Wrapper_Res_requestedExecutionLevel=RequireAdministrator

;If IsAdmin() Then MsgBox ($MB_SYSTEMMODAL, "", "The script is running with admin rights"

Example()

Func Example()

   ; Create a constant variable in Local scope of the filepath that will be read/written to.
    ;Local Const $sFilePath = "@WindowsDir & 'LOAD.txt'"
    Local Const $sFilePath = "C:WindowsLOAD.txt"

    ; Open the file for reading and store the handle to a variable.
    Local $hFileOpen = FileOpen($sFilePath, $FO_READ)
    If $hFileOpen = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
        Return False
    EndIf

    ; Read the fist line of the file using the handle returned by FileOpen.
    Local $InstalledImage = FileReadLine($hFileOpen, 1)

    ; Close the handle returned by FileOpen.
    FileClose($hFileOpen)

;MsgBox(48,"", $InstalledImage & " Is installed" ,15)
;Sleep(5000)

   Select
   Case $InstalledImage = "SMALL"
   ;FileDelete ("C:\Windows\System32\oobeinfobackgrounds*.*")
   MsgBox(48, "", "Small Image installed",15)
   FileCopy (@ScriptDir & "N-Small-background1920x1200.jpg", @DesktopDir & "background1920x1200.jpg")
   FileCopy (@ScriptDir & "N-Small-backgroundDefault.jpg", @DesktopDir & "backgroundDefault.jpg")
   Sleep(2000)
   ;FileMove (@DesktopDir & 'background.jpg', @WindowsDir & 'system32oobeinfobackgroundsbackground.jpg')
   ;FileMove (@DesktopDir & 'background1920x1200.jpg', @WindowsDir & 'system32oobeinfobackgroundsbackground1920x1200.jpg')

   Case $InstalledImage = "MEDIUM"
   MsgBox(48,"", "Medium Image installed",15)
     ;FileDelete ("C:\Windows\System32\oobeinfobackgrounds*.*")
   FileCopy (@ScriptDir & "N-Medium-background1920x1200.jpg", @DesktopDir & "background1920x1200.jpg")
   FileCopy (@ScriptDir & "N-Medium-backgroundDefault.jpg", @DesktopDir & "backgroundDefault.jpg")
   Sleep(2000)
   ;FileMove (@DesktopDir & 'background.jpg', @WindowsDir & 'system32oobeinfobackgroundsbackground.jpg')
   ;FileMove (@DesktopDir & 'background1920x1200.jpg', @WindowsDir & 'system32oobeinfobackgroundsbackground1920x1200.jpg')

   Case $InstalledImage = "LARGE"
   MsgBox(48,"", "Large Image installed",15)
     FileDelete ("C:\Windows\System32\oobeinfobackgrounds*.*")
   FileCopy (@ScriptDir & "N-Large-background1920x1200.jpg", @DesktopDir & "background1920x1200.jpg")
   FileCopy (@ScriptDir & "N-Large-backgroundDefault.jpg", @DesktopDir & "backgrounddDefault.jpg")
   Sleep(2000)
   ;FileCopy (@DesktopDir & "backgroundDefault.jpg", "C:\Windows\System32\oobeinfobackgrounds")
   ;FileCopy (@DesktopDir & "background1920x1200.jpg", "C:\Windows\System32\oobeinfobackgrounds")
   EndSelect

EndFunc

   MsgBox(48,"", "Move background files from Desktop to C:\Windows\System32\oobeinfobackgrounds",15)
   @ScriptDir run ("open folder.bat")
Exit

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Most of your script works just fine for me. I did see in this line:

Local Const $sFilePath = "@WindowsDir & '\LOAD.txt'"

You enclosed @WindowsDir in your quotes. It should be:

Local Const $sFilePath = @WindowsDir & "\LOAD.txt"

Most everything else worked once I removed all your commented lines. For the line calling your batch file:

@ScriptDir run ("open folder.bat")

should be:

Run (@ScriptDir & "\open folder.bat")

Aside from these few mistakes, I didn't see a lot that caused me trouble. Can you please let us know where else you're having problems?

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

JLogon,

Thanks for your feedback.

When I replaced

@ScriptDir Run  ("open folder.bat")

with

Run (@ScriptDir & "open folder.bat")

The error of not being able to find the target went away, but the folder did not open. As you can tell by the script, I commented out (using  ';') the lines where the script would copy the file from my desktop to the target folder. I also tried FileMove.

 

This line should copy the jpg to the 'backgrounds' folder, but nothing happens. It may be a permissions issue but I am running the script logged on as an admin.

   FileCopy (@DesktopDir & "background1920x1200.jpg", "C:\Windows\System32\oobeinfobackgrounds")

 

Thanks for the tip with reading the line

Local Const $sFilePath = @WindowsDir & "LOAD.txt"

I

I had actually used the direct path of C:WindowsLOAD.txt in the following line to work around the issue of reading this file.

 

As you can tell, LOAD.text contains either 'Small', 'Medium' or 'Large', which in turn are used to determine which backgroud files to copy over.

 

As a work around, I created three seperate batch files that do the job. The beauty of this script is that I wouldnt have to worry about running the wrong batch file since the script reads a file on the image to determine which background files to copy over.

 

 

Share this post


Link to post
Share on other sites

Can you post the contents of the batch file? Is it running and just not opening the folder, or not running at all?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Here are the contents of the batch file - one line only

     start "" "C:\Windows\System32\oobeInfoBackgrounds"

Running the batch file by itself, it opens the folder in Windows Explorer.

Running the batch file from the original script, I get the error that the folder cannot be found.

     @ScriptDir run ("open folder.bat")

Running the batch file with the suggested change to the script, nothing happens.

     Run (@ScriptDir & "open folder.bat")

Share this post


Link to post
Share on other sites

To open a folder (the name of the folder is "MailSlot").

Pretty much the same as the .bat.

ShellExecute(@ScriptDir & "\MailSlot")

Share this post


Link to post
Share on other sites

As lorenkinzel points to above, if your batch file is only the one line, better to just open the folder with AutoIt and keep .bat files out of the mix altogether.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Am I missing something...this is just a filecopy, right?


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

It is, however the OP has been adamant that he would like to open the folder in Explorer as well. See post #2 and #3.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

The only reason I am trying to open the folder is because the copy from desktop to "C:\Windows\System32\oobeInfoBackgrounds" dosnt work. Opening up the folder is a workaround.

The ultimate goal of this script is to

1. Read the contents of C:WIndows.LOAD.txt to determine what backgound images to use

2. Copy and rename the desired backgound images to the desktop

3. Move the images from the desktop to the target folder.

The backgound files are on a network share and Windows prevents copying from a network share straight to target folder. This is why the copying to the desktop was incorporated.

I hope this clears up what I am trying to accomplish.

Thanks again for all the suggestions :)

Share this post


Link to post
Share on other sites

As I mentioned in post #9, aside from a few syntax changes your script was working for me. Can you please clarify which piece isn't working (i.e. what debugging have you put in place, and on which of the 3 steps is it failing)?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

...

The backgound files are on a network share and Windows prevents copying from a network share straight to target folder. This is why the copying to the desktop was incorporated.

...

Why not copy it locally, to a temp dir, then move it to the final location?


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Try 

#RequireAdmin

$sSourceFile = @DesktopDir & "\background1920x1200.jpg"
$sDestDir = "C:\Windows\System32\oobe\Info\Backgrounds\"

FileCopy($sSourceFile,$sDestDir,1+8)

And

#RequireAdmin

$sSourceFile = @DesktopDir & "\background1920x1200.jpg"
$sDestDir = "C:\Windows\System32\oobe\Info\Backgrounds\"

If FileExists($sDestDir) = 1 Then
DirRemove($sDestDir,1)
EndIf

FileCopy($sSourceFile,$sDestDir,1+8)

One of this MUST work

Edited by GordonFreeman

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0