问题
I want to set system variable MQSERVER for connecting to MQ using QTP. Each time this value is changed from QTP, I need to restart QTP to reflect changes.
E.g. in the system variables window, MQSERVER = ABCD
change the variable using
Set objWSH = CreateObject("WScript.Shell")
Set objSystemVariables = objWSH.Environment("SYSTEM")
objSystemVariables(MQVariableName) = MQVariableValue
The variable is set correctly but does not reflect in QTP code when connecting to websphere MQ.
Immediately when I restart QTP, the QTP reads the env variable correctly. Can you please let me know how I can use the below API method. I am getting type mismatch in QTP.
lnRetVal = SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, "Environment", 2, 1000, Null) 'Getting type mismatch here
Updating my original question with the code that connects to queue manager.
The very basic thing that I am trying to do is (which can't be done without restarting QTP)
1) Connect to a queue manager
2) Put the message
3) Connect to another queue manager
4) Read the output
Const MQOO_OUTPUT = 16
Const MQOO_INPUT_AS_Q_DEF = 1
Set MQS = CreateObject("MQAX200.MQSession")
Set QM = MQS.AccessQueueManager(Environment.Value("MQName")) 'This will pass the queue name and access the queue manager.
Set MQQueue = QM.AccessQueue(strQueName, MQOO_INPUT_AS_Q_DEF Or MQOO_OUTPUT)
Set PutOptions = MQS.AccessPutMessageOptions()
PutOptions.Options = MQPMO_NO_SYNCPOINT
Set PutMsg = MQS.AccessMessage()
PutMsg.CharacterSet = 1208
PutMsg.MessageData = PutMsgStr 'the message text
PutMsg.ApplicationIdData = "INTF_0439B"
MQQueue.Put PutMsg, PutOptions 'write the message to queue.
Also, my websphere MQ version is 7.0.1.8
来源:https://stackoverflow.com/questions/44627702/refresh-system-variable-using-vbscript-qtp