Need to convert bat script to Macroscheduler. Help needed

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
Morten Nissen
Newbie
Posts: 9
Joined: Thu Aug 25, 2005 12:46 pm

Need to convert bat script to Macroscheduler. Help needed

Post by Morten Nissen » Fri Sep 13, 2013 1:01 pm

Hi.

I want to convert a bat script into macroscheduler so I can make a .exe file of it.

It's because we have problem with Outlook 2007 will not remember the password and it ask for it every time we start Outlook. This is because out Exchange system is hosted and they have 2 diffent domains. One for the Proxy and one for the Exchange servers.

So we need this small script so it will enter the credentials info the credential manager in windows and the user only need to type the mail adress and the password and it's saved in the crendetial manager under Control panel / user /manage your credentials (i Think that it's something like that in English windows).

Anyone of the experts that can help me with this. I can't make it work in Macro Scheduler.

This is the bat script that we have now that works. The problem is we need Swedish chars and we can't get that in dos in an easy way. So I want to do it in Macroscheduler that we already use for long time for automation.

Code: Select all


@ECHO OFF
set /p un=Write your E-mail adress and press ENTER: 
set /p pw=Write your E-mail password and press ENTER: 
@ECHO ON
cmdkey /add: *.hostingdomaine1.local /user:%un% /pass:%pw%
cmdkey /add: *.hostingdomaine2.com /user:%un /pass:%pw%


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

Post by JRL » Fri Sep 13, 2013 1:36 pm

Something like this help? I'm assuming you are on version 12 or later. Also assuming the Swedish character issue is because of the DOS "set" command limitations. But I have no way to test that theory.

This uses a dialog to get the login info then passes it to the working portion of the batch file text. We then write the text to a file.bat and run the batch file. When the batch file is finished we delete it.

This could be made more robust but at this time we just need to find out if it will work.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 433
  Top = 150
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Login'
  ClientHeight = 186
  ClientWidth = 285
  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 Label1: TLabel
    Left = 72
    Top = 32
    Width = 53
    Height = 13
    Caption = 'User Name'
  end
  object Label2: TLabel
    Left = 72
    Top = 80
    Width = 46
    Height = 13
    Caption = 'Password'
  end
  object Label3: TLabel
    Left = 40
    Top = 8
    Width = 3
    Height = 13
  end
  object Edit1: TEdit
    Left = 74
    Top = 48
    Width = 121
    Height = 21
    TabOrder = 0
  end
  object Edit2: TEdit
    Left = 73
    Top = 99
    Width = 121
    Height = 21
    TabOrder = 1
  end
  object MSButton1: tMSButton
    Left = 94
    Top = 145
    Width = 75
    Height = 25
    Caption = 'Ok'
    TabOrder = 2
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,msButton1,OnClick,Process

Show>Dialog1,res1

SRT>Process
  GetDialogProperty>Dialog1,Edit1,test,un
  GetDialogProperty>Dialog1,Edit2,text,pw
  LabelToVar>BatchFile,vData
  WriteLn>%temp_dir%SomeWeirdName.bat,wres,vData
  Let>RP_Wait=1
  Let>RP_Windowmode=0
  RunProgram>%temp_dir%SomeWeirdName.bat
  Wait>0.5
  DeleteFile>%temp_dir%SomeWeirdName.bat
END>Process

/*
BatchFile:
cmdkey /add: *.hostingdomaine1.local /user:%un% /pass:%pw%
cmdkey /add: *.hostingdomaine2.com /user:%un /pass:%pw%
*/

Morten Nissen
Newbie
Posts: 9
Joined: Thu Aug 25, 2005 12:46 pm

Post by Morten Nissen » Tue Sep 17, 2013 10:03 am

JRL wrote:Something like this help? I'm assuming you are on version 12 or later. Also assuming the Swedish character issue is because of the DOS "set" command limitations. But I have no way to test that theory.

This uses a dialog to get the login info then passes it to the working portion of the batch file text. We then write the text to a file.bat and run the batch file. When the batch file is finished we delete it.

This could be made more robust but at this time we just need to find out if it will work.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 433
  Top = 150
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Login'
  ClientHeight = 186
  ClientWidth = 285
  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 Label1: TLabel
    Left = 72
    Top = 32
    Width = 53
    Height = 13
    Caption = 'User Name'
  end
  object Label2: TLabel
    Left = 72
    Top = 80
    Width = 46
    Height = 13
    Caption = 'Password'
  end
  object Label3: TLabel
    Left = 40
    Top = 8
    Width = 3
    Height = 13
  end
  object Edit1: TEdit
    Left = 74
    Top = 48
    Width = 121
    Height = 21
    TabOrder = 0
  end
  object Edit2: TEdit
    Left = 73
    Top = 99
    Width = 121
    Height = 21
    TabOrder = 1
  end
  object MSButton1: tMSButton
    Left = 94
    Top = 145
    Width = 75
    Height = 25
    Caption = 'Ok'
    TabOrder = 2
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,msButton1,OnClick,Process

Show>Dialog1,res1

SRT>Process
  GetDialogProperty>Dialog1,Edit1,test,un
  GetDialogProperty>Dialog1,Edit2,text,pw
  LabelToVar>BatchFile,vData
  WriteLn>%temp_dir%SomeWeirdName.bat,wres,vData
  Let>RP_Wait=1
  Let>RP_Windowmode=0
  RunProgram>%temp_dir%SomeWeirdName.bat
  Wait>0.5
  DeleteFile>%temp_dir%SomeWeirdName.bat
END>Process

/*
BatchFile:
cmdkey /add: *.hostingdomaine1.local /user:%un% /pass:%pw%
cmdkey /add: *.hostingdomaine2.com /user:%un /pass:%pw%
*/
Hi.

Thanks alot. I have been away and haven't had the time to look at this again and reply to you.

It look good but there seems to be some errors in the script as it don't write the info right as you can see here.

Image

Användarenamn is Username and Lösenord is Password

Any idea where it goes wrong?

Morten Nissen
Newbie
Posts: 9
Joined: Thu Aug 25, 2005 12:46 pm

Post by Morten Nissen » Tue Sep 17, 2013 10:24 am

I found that there was a % missing in the last line. but still it gives me NO_SUCH_PROBPRTY on both entrys.

Anyway the make the dialog go away (colse/end) efter pressing Ok?

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Tue Sep 17, 2013 2:41 pm

The problem was a simple typo. GetDialogProperty>Dialog1,Edit1,test,un should be GetDialogProperty>Dialog1,Edit1,text,un

Code: Select all

SRT>Process
  GetDialogProperty>Dialog1,Edit1,text,un
  GetDialogProperty>Dialog1,Edit2,text,pw
  LabelToVar>BatchFile,vData
  WriteLn>%temp_dir%SomeWeirdName.bat,wres,vData
  Let>RP_Wait=1
  Let>RP_Windowmode=0
  RunProgram>%temp_dir%SomeWeirdName.bat
  Wait>0.5
  DeleteFile>%temp_dir%SomeWeirdName.bat
END>Process

As to your other question.
If you want to exit the script, add Exit>1 at the end of the subroutine like so...

Code: Select all

SRT>Process
  GetDialogProperty>Dialog1,Edit1,text,un
  GetDialogProperty>Dialog1,Edit2,text,pw
  LabelToVar>BatchFile,vData
  WriteLn>%temp_dir%SomeWeirdName.bat,wres,vData
  Let>RP_Wait=1
  Let>RP_Windowmode=0
  RunProgram>%temp_dir%SomeWeirdName.bat
  Wait>0.5
  DeleteFile>%temp_dir%SomeWeirdName.bat
  Exit>1
END>Process
Do this if all you want is to hide the dialog while the subroutine is being executed...

Code: Select all

SRT>Process
  //Hide dialog by settings visibility to false
  SetDialogProperty>Dialog1,,Visible,False

  GetDialogProperty>Dialog1,Edit1,text,un
  GetDialogProperty>Dialog1,Edit2,text,pw
  LabelToVar>BatchFile,vData
  WriteLn>%temp_dir%SomeWeirdName.bat,wres,vData
  Let>RP_Wait=1
  Let>RP_Windowmode=0
  RunProgram>%temp_dir%SomeWeirdName.bat
  Wait>0.5
  DeleteFile>%temp_dir%SomeWeirdName.bat

  //Show dialog by settings visibility to false
  SetDialogProperty>Dialog1,,Visible,True
END>Process

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

Post by JRL » Wed Sep 18, 2013 4:45 am

The problem was a simple typo. GetDialogProperty>Dialog1,Edit1,test,un should be GetDialogProperty>Dialog1,Edit1,text,un
Sorry, Should never post untested code.

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