Very Interesting

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
PepsiHog
Automation Wizard
Posts: 517
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Very Interesting

Post by PepsiHog » Sun Feb 24, 2013 3:49 am

Hello,

Here is a macro I wrote. I wrote it using v12.1.10. It's a simple macro. All it does is change the default location where programs are installed. The default being C:\Program Files. You can choose another location as your default.

Only tested for Windows XP. Be carefull if your not using XP. I don't know if the settings are the same in other Windows.

See continued post after this script>>>>

Code: Select all

Let>VAREXPLICIT=1
let>RootKey=HKEY_LOCAL_MACHINE
let>Key=\SOFTWARE\Microsoft\Windows\CurrentVersion
LabelToVar>OutputScript,ProgramScript

Dialog>Dialog1
object Dialog1: TForm
  Left = 251
  Top = 104
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Default Program Path'
  ClientHeight = 66
  ClientWidth = 466
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  Menu = MainMenu
  OldCreateOrder = True
  Position = poDesktopCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Edit1: TEdit
    Left = 16
    Top = 24
    Width = 280
    Height = 21
    TabOrder = 0
  end
  object MSButton1: tMSButton
    Left = 304
    Top = 20
    Width = 33
    Height = 25
    DoubleBuffered = True
    Glyph.Data = {
      F6000000424DF600000000000000760000002800000010000000100000000100
      0400000000008000000000000000000000001000000010000000000000000000
      80000080000000808000800000008000800080800000C0C0C000808080000000
      FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
      77777777777777777777000000000007777700333333333077770B0333333333
      07770FB03333333330770BFB0333333333070FBFB000000000000BFBFBFBFB07
      77770FBFBFBFBF0777770BFB0000000777777000777777770007777777777777
      7007777777770777070777777777700077777777777777777777}
    ParentDoubleBuffered = False
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 345
    Top = 20
    Width = 50
    Height = 25
    Caption = 'Cancel'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 2
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton3: tMSButton
    Left = 399
    Top = 20
    Width = 50
    Height = 25
    Caption = 'Apply'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 3
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MainMenu: tMSMainMenu
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = []
    object MenuItem1: tMSMenuItem
      Caption = 'Script'
      object MenuItem2: tMSMenuItem
        Caption = 'View'
      end
      object MenuItem3: tMSMenuItem
        Caption = 'Print'
      end
    end
  end
end
EndDialog>Dialog1

Dialog>Dialog5
object Dialog5: TForm
  Left = 426
  Top = 146
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'View Script'
  ClientHeight = 216
  ClientWidth = 439
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSMemo1: tMSMemo
    Left = 0
    Top = 0
    Width = 439
    Height = 216
    Align = alClient
    ScrollBars = ssBoth
    TabOrder = 0
  end
end
EndDialog>Dialog5

AddDialogHandler>Dialog1,MSButton1,OnClick,DoBrowse
AddDialogHandler>Dialog1,MSButton2,OnClick,DoExit
AddDialogHandler>Dialog1,MSButton3,OnClick,DoApply
AddDialogHandler>Dialog1,MenuItem2,OnClick,DoView
AddDialogHandler>Dialog1,MenuItem3,OnClick,DoLocation

RegistryReadKey>%RootKey%,%Key%,ProgramFilesDir,ProgramFilesDir

SetDialogProperty>Dialog1,Edit1,Text,%ProgramFilesDir%

Show>Dialog1,r

srt>DoApply
LibFunc>user32,MessageBoxA,res,0,Changing to : %ProgramFilesDir%%crlf%Are you sure?,Change Default Program Location,35
if>%res%=6
RegistryWriteKey>%RootKey%,%Key%,ProgramFilesDir,%ProgramFilesDir%
endif
if>%res%=2
    GoSub>DoExit
endif
END>DoApply

SRT>DoBrowse
  SetDialogProperty>Dialog1,MSButton1,InitialDir,%ProgramFilesDir%
  SetDialogProperty>Dialog1,MSButton1,BrowseStyle,fbFolder
  SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
  SetDialogProperty>Dialog1,MSButton1,InitialDir,%ProgramFilesDir%
  GetDialogProperty>Dialog1,MSButton1,Filename,ProgramFilesDir
  SetDialogProperty>Dialog1,Edit1,Text,%ProgramFilesDir%
END>DoBrowse

SRT>DoLocation
  LibFunc>user32,MessageBoxA,r,0,Please choose destination folder for script.,Print Script,64
  SetDialogProperty>Dialog1,MSButton1,InitialDir,%Desktop_Dir%
  SetDialogProperty>Dialog1,MSButton1,BrowseStyle,fbFolder
  SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
  GetDialogProperty>Dialog1,MSButton1,Filename,ScriptLocation
  WriteLn>%ScriptLocation%\Program_Script.txt,wtf,%ProgramScript%
  if>%wtf%=0
     LibFunc>user32,MessageBoxA,r,0,       Script has been sucessfully written to -%crlf%%ScriptLocation%    %crlf%       Filename = Program_Script.txt,Success,64
   else
     LibFunc>user32,MessageBoxA,r,0,Unable to write script. Try again.(%wtf%),Write Failed!,16
  endif
END>DoLocation

srt>DoView
  SetDialogProperty>Dialog5,MSMemo1,Text,%ProgramScript%
  Show>Dialog5,b
END>DoView

srt>DoExit
  exit
END>DoExit

/*
OutputScript:
Let>VAREXPLICIT=1
let>RootKey=HKEY_LOCAL_MACHINE
let>Key=\SOFTWARE\Microsoft\Windows\CurrentVersion
LabelToVar>OutputScript,ProgramScript

Dialog>Dialog1
object Dialog1: TForm
  Left = 251
  Top = 104
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Default Program Path'
  ClientHeight = 66
  ClientWidth = 466
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  Menu = MainMenu
  OldCreateOrder = True
  Position = poDesktopCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Edit1: TEdit
    Left = 16
    Top = 24
    Width = 280
    Height = 21
    TabOrder = 0
  end
  object MSButton1: tMSButton
    Left = 304
    Top = 20
    Width = 33
    Height = 25
    DoubleBuffered = True
    Glyph.Data = {
      F6000000424DF600000000000000760000002800000010000000100000000100
      0400000000008000000000000000000000001000000010000000000000000000
      80000080000000808000800000008000800080800000C0C0C000808080000000
      FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
      77777777777777777777000000000007777700333333333077770B0333333333
      07770FB03333333330770BFB0333333333070FBFB000000000000BFBFBFBFB07
      77770FBFBFBFBF0777770BFB0000000777777000777777770007777777777777
      7007777777770777070777777777700077777777777777777777}
    ParentDoubleBuffered = False
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 345
    Top = 20
    Width = 50
    Height = 25
    Caption = 'Cancel'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 2
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton3: tMSButton
    Left = 399
    Top = 20
    Width = 50
    Height = 25
    Caption = 'Apply'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 3
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MainMenu: tMSMainMenu
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = []
    object MenuItem1: tMSMenuItem
      Caption = 'Script'
      object MenuItem2: tMSMenuItem
        Caption = 'View'
      end
      object MenuItem3: tMSMenuItem
        Caption = 'Print'
      end
    end
  end
end
EndDialog>Dialog1

Dialog>Dialog5
object Dialog5: TForm
  Left = 426
  Top = 146
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'View Script'
  ClientHeight = 216
  ClientWidth = 439
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSMemo1: tMSMemo
    Left = 0
    Top = 0
    Width = 439
    Height = 216
    Align = alClient
    ScrollBars = ssBoth
    TabOrder = 0
  end
end
EndDialog>Dialog5

AddDialogHandler>Dialog1,MSButton1,OnClick,DoBrowse
AddDialogHandler>Dialog1,MSButton2,OnClick,DoExit
AddDialogHandler>Dialog1,MSButton3,OnClick,DoApply
AddDialogHandler>Dialog1,MenuItem2,OnClick,DoView
AddDialogHandler>Dialog1,MenuItem3,OnClick,DoLocation

RegistryReadKey>%RootKey%,%Key%,ProgramFilesDir,ProgramFilesDir

SetDialogProperty>Dialog1,Edit1,Text,%ProgramFilesDir%

Show>Dialog1,r

srt>DoApply
LibFunc>user32,MessageBoxA,res,0,Changing to : %ProgramFilesDir%%crlf%Are you sure?,Change Default Program Location,35
if>%res%=6
RegistryWriteKey>%RootKey%,%Key%,ProgramFilesDir,%ProgramFilesDir%
endif
if>%res%=2
    GoSub>DoExit
endif
END>DoApply

SRT>DoBrowse
  SetDialogProperty>Dialog1,MSButton1,InitialDir,%ProgramFilesDir%
  SetDialogProperty>Dialog1,MSButton1,BrowseStyle,fbFolder
  SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
  SetDialogProperty>Dialog1,MSButton1,InitialDir,%ProgramFilesDir%
  GetDialogProperty>Dialog1,MSButton1,Filename,ProgramFilesDir
  SetDialogProperty>Dialog1,Edit1,Text,%ProgramFilesDir%
END>DoBrowse
*/

/*

SRT>DoLocation
  LibFunc>user32,MessageBoxA,r,0,Please choose destination folder for script.,Print Script,64
  SetDialogProperty>Dialog1,MSButton1,InitialDir,%Desktop_Dir%
  SetDialogProperty>Dialog1,MSButton1,BrowseStyle,fbFolder
  SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
  GetDialogProperty>Dialog1,MSButton1,Filename,ScriptLocation
  WriteLn>%ScriptLocation%\Program_Script.txt,wtf,%ProgramScript%
  if>%wtf%=0
     LibFunc>user32,MessageBoxA,r,0,       Script has been sucessfully written to -%crlf%%ScriptLocation%    %crlf%       Filename = Program_Script.txt,Success,64
   else
     LibFunc>user32,MessageBoxA,r,0,Unable to write script. Try again.(%wtf%),Write Failed!,16
  endif
END>DoLocation

srt>DoView
  SetDialogProperty>Dialog5,MSMemo1,Text,%ProgramScript%
  Show>Dialog5,b
END>DoView

srt>DoExit
  exit
END>DoExit
*/

Also, there is a wierd thing that happens. See if it happens with you. Be sure you're running v12.1.10. There are two comment blocks. The intent was to have a way to view or print the script after it was an .exe.

Try adding Block 2 (the last comment block) to the bottom of block 1. Then run the script. Did you get an error?

I keep getting an error that says "Line 5 variable refers to itself......"

Between the two blocks just remove the */ and /* to make it one comment block. I even cut and pasted it, and still got an error.


Please post your results,
PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Sun Feb 24, 2013 6:53 am

These are the lines causing the error. This is what is going on. You are setting "ProgramScript" to, in this case, attempt to write itself to a file. It's confused.

Code: Select all

LabelToVar>OutputScript,ProgramScript
/*
OutputScript:
LabelToVar>OutputScript,ProgramScript
WriteLn>%temp_dir%Program_Script.txt,wtf,%ProgramScript%
*/
The intent was to have a way to view or print the script after it was an .exe.
Have you seen my post on the subject of extracting the original script from an exe? I have provided an exe that can use your compiler to create exes capable of writing out the original script. Once you download Extract_Compile.exe from SkyDrive you can extract its embedded script using "JRL" as the password. I have the script on the Macro Scheduler main menu with a hot key. I use it to compile every script I compile.

User avatar
PepsiHog
Automation Wizard
Posts: 517
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Hello

Post by PepsiHog » Sun Feb 24, 2013 8:22 pm

@JRL

Thanks. Yes, I have seen your post. I just realized that I was confusing ImportData with LabelToVar. That's what I was thinking I was doing.

But how is it getting confused? Isn't it just bringing the data into a variable? It shouldn't be using or examining it. It's just a var.

OK, how am I confused now? What am I missing here? I did see a post about using vars to execute code, that hasn't been created yet, has it?

I was aware of your post, but I wanted it to be done through the window, not with the slash option. A little something different.

Thanks for your time and help,
PepsiHog
Always apprieciated.
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts