Quantcast

Maximum PC

It is currently Sat Oct 25, 2014 5:50 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 55 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Creating a BAT file to replace a system file
PostPosted: Mon Oct 27, 2008 8:31 am 
Team Member Top 500
Team Member Top 500
User avatar

Joined: Thu Dec 23, 2004 2:34 pm
Posts: 3977
Location: Building my 4-8-9
The system file in question is shellstyle.dll. I have four different colored shells I like to use depending on the season. How would I write a simple BAT to replace the file, which is located at C:\Windows\Resources\Themes\Aero\Shell\NormalColor?


Top
  Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2008 8:38 am 
Smithfield
Smithfield
User avatar

Joined: Sat Jun 26, 2004 2:47 am
Posts: 10158
Location: Between 32nd Notes
So you have four separate shellstyle.dll files that you want to copy and replace to the proper location using a batch file?

Do you want a menu to pop up or do you want 4 individual batch files?


Top
  Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2008 9:05 am 
Smithfield
Smithfield
User avatar

Joined: Sat Jun 26, 2004 2:47 am
Posts: 10158
Location: Between 32nd Notes
Here's a link to Batch file commands. Scroll down and it has an example of Menu Creation with copying.


Top
  Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2008 9:19 am 
Team Member Top 500
Team Member Top 500
User avatar

Joined: Thu Dec 23, 2004 2:34 pm
Posts: 3977
Location: Building my 4-8-9
Copy ONE DLL and overwrite ONE DLL.

The locations of the files to be copied are known and static, as is the location they are going to be copied to. I don't need a menu, just a confirmation that the overwrite was successful or not.

Code:
COPY shellstyle.dll C:\Windows\Resources\Themes\Aero\Shell\NormalColor
assuming the BAT is in the same directory as the DLL, would that work? Now all I need is a confirmation to tell me if the overwrite was successful or not...


Top
  Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2008 9:27 am 
Smithfield
Smithfield
User avatar

Joined: Sat Jun 26, 2004 2:47 am
Posts: 10158
Location: Between 32nd Notes
Since it's running in a DOS window try adding the command PAUSE after the copy command.

This will make the batch file wait for user input. Basically a "Press Any Key To Continue".

The regular DOS copy messages should display until you press a key.


Top
  Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2008 11:47 am 
Team Member Top 500
Team Member Top 500
User avatar

Joined: Thu Dec 23, 2004 2:34 pm
Posts: 3977
Location: Building my 4-8-9
Is there a way to make a more complicated program? Something like this...

- Program asks what theme you want to change to (Fall, Winter, Spring, Summer)
- Pick the theme
- Theme changed to Windows Classic
- DLL file copied in
- Theme changed back to Windows Vista

That seems a bit much for a .BAT though.


Top
  Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2008 12:15 pm 
Smithfield
Smithfield
User avatar

Joined: Sat Jun 26, 2004 2:47 am
Posts: 10158
Location: Between 32nd Notes
That's what I showed you with that link.

The Menu example is very close to what you want to do.


Top
  Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2008 3:29 pm 
Team Member [Top 500]*
Team Member [Top 500]*
User avatar

Joined: Thu Jun 24, 2004 2:22 pm
Posts: 8720
Location: Cleveland, Ohio
Soverign & Satch I don't want to hijack this but I have a thought on this. Soverign if you would consider a .VBS file to get things done I may have something. Several years ago for reasons I don't even remember I wanted to do something similiar. I wrote a small program for people to install from a floppy and did it this way:

Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='A:\Package'} Where " _
        & "ResultClass = CIM_DataFile")

For Each objFile in colFiles
    If objFile.Extension = "ini" Then
        strCopy = "F:\WINDOWS\system32\" & objFile.FileName _
            & "." & objFile.Extension
        objFile.Copy(strCopy)
        objFile.Delete
    End If
    If objFile.Extension = "bmp" Then
        strCopy = "F:\WINDOWS\system32\" & objFile.FileName _
            & "." & objFile.Extension
        objFile.Copy(strCopy)
        objFile.Delete
    End If
Next


The floppy file was "Package" and it would move the file to the System32 folder. However the objfile.Delete was rem out as in:

'objFile.Delete

Now if you want a notification the following code can easily be modified:

Code:
' MoveFSO.vbs
' Example script to move files.
' Author Guy Thomas http://computerperformance.co.uk/
' Version 4.2 - 4th July 2004
' -------------------------------------------------------------'
Option Explicit

Dim objFSO, objFileCopy, objGuyFile, objFileDelete
Dim strFilePath, strDestination
Dim strFileText, strFileText2, strFileText3

strFilePath = "e:\ezine\scripts\ezine36\newsletter36.txt"
strDestination ="e:\ezine\scripts\ezine36\4thJuly.txt"
strFileText = "Today is American Independence day "
strFileText2 = "Next Ezine 11 July"
strFileText3 = " Bye from Guy"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objGuyFile = objFSO.CreateTextFile(strFilePath, True)

objGuyFile.WriteLine(strFileText)
objGuyFile.Write (strFileText2)
objGuyFile.WriteLine (strFileText3)
objGuyFile.Close

WSCript.Echo "Written " & strFileText & " to " & strFilePath

' Delete file if it alread exists in the destination.
Set objFileCopy = objFSO.GetFile(strDestination)
objFileCopy.Delete ()

Set objFileCopy = objFSO.GetFile(strFilePath)
' Move the file destination

objFileCopy.Move (strDestination)
WSCript.Echo "Copied to " & strDestination
Wscript.Quit

' End of example Script


Use the ECHO to get a result and modify the code. Either can be tweaked to move a file.

For what it is worth if you toss in a date function with a few If lines it could change the files by date.

<EDIT> The second example is from here:

http://www.computerperformance.co.uk/ezine/ezine36.htm

I forgot to include that! </EDIT>

Ron


Top
  Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2008 6:42 pm 
Team Member Top 500
Team Member Top 500
User avatar

Joined: Thu Dec 23, 2004 2:34 pm
Posts: 3977
Location: Building my 4-8-9
.BAT was the only think I could think of, but Ron your comments are most welcome. My point isn't so much that I need a .BAT but that I want something automatic...


Top
  Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2008 1:17 am 
Team Member [Top 500]*
Team Member [Top 500]*
User avatar

Joined: Thu Jun 24, 2004 2:22 pm
Posts: 8720
Location: Cleveland, Ohio
Then I would consider writing a VBScript file. You could maybe use a Date function with some decision making in the code. Either of the above code samples will move a file. Just a matter of adding more code. Something like

Dim Summer, Winter, Spring, Fall As Date

Summer = 6/21
Winter = 12/21
Whatever.....



If Date = Summer Then
[Statements]
Else If Date = Fall Then
[Statemenmts}

Else Quit

Something like that might work?

Keep in mind I am far from a programmer type. :lol: Also I just woke up for work today but something like this may work for you.

Ron


Top
  Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2008 10:23 am 
Team Member Top 500
Team Member Top 500
User avatar

Joined: Thu Dec 23, 2004 2:34 pm
Posts: 3977
Location: Building my 4-8-9
Reloadron wrote:
Then I would consider writing a VBScript file. You could maybe use a Date function with some decision making in the code. Either of the above code samples will move a file. Just a matter of adding more code. Something like

Dim Summer, Winter, Spring, Fall As Date

Summer = 6/21
Winter = 12/21
Whatever.....



If Date = Summer Then
[Statements]
Else If Date = Fall Then
[Statemenmts}

Else Quit

Something like that might work?

Keep in mind I am far from a programmer type. :lol: Also I just woke up for work today but something like this may work for you.

Ron


I gave up on programming a year ago, so you're ahead of me... I will see how well this works when I am out of the office today.


Top
  Profile  
 
 Post subject:
PostPosted: Thu Oct 30, 2008 2:09 pm 
Team Member [Top 500]*
Team Member [Top 500]*
User avatar

Joined: Thu Jun 24, 2004 2:22 pm
Posts: 8720
Location: Cleveland, Ohio
Soverign if you want to pursue this let me know and I will post some better code samples.

Ron


Top
  Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2008 8:44 pm 
Team Member Top 500
Team Member Top 500
User avatar

Joined: Thu Dec 23, 2004 2:34 pm
Posts: 3977
Location: Building my 4-8-9
Please do, this weekend contains no actual pressing homework so I'm gonna give this a serious shot (since I'm on the verge of changing to Winter theme anyway).


Top
  Profile  
 
 Post subject:
PostPosted: Sat Nov 01, 2008 2:57 pm 
Team Member [Top 500]*
Team Member [Top 500]*
User avatar

Joined: Thu Jun 24, 2004 2:22 pm
Posts: 8720
Location: Cleveland, Ohio
OK, here is some of what I did today as a basic start. I created a very simple .vbs file to copy a file. The basic code looks like this:

Code:
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "C:\MyThemes\shellstyle.dll" ,_
"C:\Windows\Resources\Themes\Aero\Shell\NormalColor\shellstyle.dll", OverwriteExisting


You can see I created a folder on the root of my C:\ drive named MyThemes and shoved the shellstyle.dll file in it. You can try the same.

Copy and Paste the code sample into Notepad. Then Save As something like MoveFile.vbs but be sure to add the file extension .vbs or notepad will save it as a text file. Save the file to your desktop (for convenience). Doubleclick the file to run it.

Additionally I had to take ownership of the file and allow permissions to overwrite it. Vista is fussy about system files. This is for Vista correct?

The problem I have is the file copies fine and removes the existing destination file. However even with the new file in place nothing happens?

Ron


Top
  Profile  
 
 Post subject:
PostPosted: Sun Nov 02, 2008 7:02 am 
Team Member Top 500
Team Member Top 500
User avatar

Joined: Thu Dec 23, 2004 2:34 pm
Posts: 3977
Location: Building my 4-8-9
You have the solution to my problem and I know what's going on for you. In order to avoid having to reboot the system, you must change the theme to Windows Classic. This unloads shellstyle.dll from memory (I'm surprised you can overwrite it while Aero is on). Change to Classic, replace the DLL, reload Aero. The customized shellstyle will kick in effective immediately.

I'm going to see if there's an automatic way to change the theme (because I don't think changing to Aero Basic is going to cut it, otherwise that can be done with Vista itself).

EDIT: There isn't, but there's a shortcut to open the Themes portion of the Control Panel. I need a way to pause the script while the Themes section is open and only continue AFTER it has been closed (because we assume the user follows the instructions and makes the change).

Code:
Dim j As String = "This script will launch your Themes Control Panel.  Please change your theme to Windows Classic."

// Note I'm not sure this is right, I found something for launching EXEs
// and modified it.
Private Sub cmd_ThemeChange
Dim dSomeReturnValue as Double
dSomeReturnValue = Shell("C:\Windows\System32\control.exe desk.cpl,,@themes", vbNormalFocus)
End Sub
<-----NEED PAUSE HERE----->
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "C:\Users\Nate\Driver Cache\Seasonal Theming\Winter\shellstyle.dll" ,_
"C:\Windows\Resources\Themes\Aero\Shell\NormalColor\shellstyle.dll", OverwriteExisting

*Pseudocode*
Display confirmation of file overwrite and a message "The file was overwritten successfully."

Tell user that the Themes control panel will open again, change back to Windows Vista to see the result.


Top
  Profile  
 
 Post subject:
PostPosted: Sun Nov 02, 2008 7:32 am 
Team Member [Top 500]*
Team Member [Top 500]*
User avatar

Joined: Thu Jun 24, 2004 2:22 pm
Posts: 8720
Location: Cleveland, Ohio
This may work:

Code:
Dim j As String = "This script will launch your Themes Control Panel.  Please change your theme to Windows Classic."
Private Sub cmd_ThemeChange
Dim dSomeReturnValue as Double
dSomeReturnValue = Shell("C:\Windows\System32\control.exe desk.cpl,,@themes", vbNormalFocus)
End Sub
WScript.Sleep 5000
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "C:\Users\Nate\Driver Cache\Seasonal Theming\Winter\shellstyle.dll" ,_
"C:\Windows\Resources\Themes\Aero\Shell\NormalColor\shellstyle.dll", OverwriteExisting


The WScript.Sleep will create a pause in milli-seconds. The WScript.Sleep I use above will create a 5 second delay (pause) in the running script. Another option might be using a Do Until followed by the Obj.

I used the sleep before in a script to open a browser and alternate between two websites.

Nice piece of work there!

Ron


Top
  Profile  
 
 Post subject:
PostPosted: Sun Nov 02, 2008 8:01 am 
Team Member Top 500
Team Member Top 500
User avatar

Joined: Thu Dec 23, 2004 2:34 pm
Posts: 3977
Location: Building my 4-8-9
Running on desktop (where I know it won't work because the filepaths aren't constructed yet) I get:
Code:
Line: 1
Char: 7
Error: Expected end of statement
Code: 800A0401
Source: Microsoft VBScript compilation error


I know later on I will get a "File not found" error or something but this is well before any files are actually replaced...


Top
  Profile  
 
 Post subject:
PostPosted: Sun Nov 02, 2008 2:34 pm 
Team Member [Top 500]*
Team Member [Top 500]*
User avatar

Joined: Thu Jun 24, 2004 2:22 pm
Posts: 8720
Location: Cleveland, Ohio
I should have caught that but just inserted the pause. OK you have a few options and I would do it this way for a basic option:

Quote:
Dim j
j = "This script will launch your Themes Control Panel. Please change your theme to Windows Classic."
MsgBox (j)


That gives the user a single choice as in VB OK. WE could expand on that and give the user a few options:

Quote:
Dim j
j = MsgBox("This script will launch your Themes Control Panel. Please change your theme to Windows Classic.",1)


The number of buttons increased and we added the option to Cancel to the user.

Here we add a title to the MsgBox:

Quote:
Dim j
j = MsgBox("This script will launch your Themes Control Panel. Please change your theme to Windows Classic."_
,1,"Change To Windows Classic!")


See if that helps.

<EDIT> How about Code, Code, Code instead of Quote, Quote, Quote! Damn, it's been a long day! :lol: </EDIT>

Ron


Top
  Profile  
 
 Post subject:
PostPosted: Sun Nov 02, 2008 3:25 pm 
Team Member Top 500
Team Member Top 500
User avatar

Joined: Thu Dec 23, 2004 2:34 pm
Posts: 3977
Location: Building my 4-8-9
Ron, thank you for all your help. I will be implementing this as soon as I get back from dinner and a meeting...


Top
  Profile  
 
 Post subject:
PostPosted: Sun Nov 02, 2008 5:10 pm 
Team Member [Top 500]*
Team Member [Top 500]*
User avatar

Joined: Thu Jun 24, 2004 2:22 pm
Posts: 8720
Location: Cleveland, Ohio
OK, and if you want to get cool with this little project and actually create a little program in VB.NET with a Form and Buttons you can snag VB.NET 2008 the Express edition for free here:

http://www.microsoft.com/express/vb/

The express editions of the entire .NET suite are not as robust as the Professional and better editiona but free is a good price and you can do quite a bit with it.

Generally I create most of my stuff (basic data acquisition stuff) using VB 6.0 although I have the entire .NET Professional suite. However, I have been screwing with this using the VB.NET Express 2005 edition and actually it can be pretty cool.

Something for thought...

Ron


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 55 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

© 2014 Future US, Inc. All rights reserved.