Is there a way to require admin in Autoit only if statement is true?
I tried
Global $a = 0
If $a == 1 Then
#RequireAdmin
EndIf
But that doesn't seem to work, it still asks for Admin rights.
If it's no problem if there are more files:
$a = 1
If($a = 1) Then
Run(Run Script with #RequireAdmin)
Else
Run(Run Script without #RequireAdmin)
EndIf
you could use this:
#include <MsgBoxConstants.au3>
If IsAdmin() Then
MsgBox($MB_SYSTEMMODAL, "", "IsAdmin" & #CRLF & "Admin rights are detected.")
EndIf
If not isAdmin and your var = true then ...
Related
I can do simple checks with make's conditionals, like that:
var = yes
ifeq $(var) "yes"; then
echo "yes"
else
echo "no"
fi
But the docs say nothing about elif. Can I do it like the following ?
var = yes
ifeq $(var) "yes"; then
echo "yes"
elifeq $(var) "no"; then
echo "no"
else
echo "invalid"
fi
If not, is that possible at all, or do I have to make nested conditions or use test ?
Can I do it like the following ?
No. You cannot use elifeq.
do I have to make nested conditions or use test ?
No. The documentation says:
The syntax of a complex conditional is as follows:
...
or:
conditional-directive-one
text-if-one-is-true
else conditional-directive-two
text-if-two-is-true
else
text-if-one-and-two-are-false
endif
There can be as many “else conditional-directive” clauses as necessary.
Note here it says else conditional-directive-two. So, you can write:
var = yes
ifeq ($(var),yes)
$(info "yes")
else ifeq ($(var),no)
$(info "no")
else
$(info "invalid")
endif
Note your original syntax is not valid makefile syntax. It looks like you're trying to use shell syntax: a makefile is not a shell script and doesn't use the same syntax.
My AutoIt script opens an Excel file and moves it to desktop, but I found a problem if that Excel file was already open, so for that I need to add in my code a condition to pass if Excel file was opened.
My code :
#include<excel.au3>
Func _WinWaitActivate($title,$text,$timeout=0)
WinWait($title,$text,$timeout)
If Not WinActive($title,$text) Then WinActivate($title,$text)
WinWaitActive($title,$text,$timeout)
EndFunc
Func _Au3RecordSetup()
Opt('WinWaitDelay',100)
Opt('WinDetectHiddenText',1)
Opt('MouseCoordMode',0)
Local $aResult = DllCall('User32.dll', 'int', 'GetKeyboardLayoutNameW', 'wstr', '')
If $aResult[1] <> '0000040C' Then
MsgBox(64, 'Warning', 'Recording has been done under a different Keyboard layout' & #CRLF & '(0000040C->' & $aResult[1] & ')')
EndIf
EndFunc
HotKeySet("{F2}", "COMP")
Func COMP()
local $var = "C:\Users\Relkassah\Desktop\changment data.xlsx"
local $oExcel_1 = _Excel_Open()
_Excel_BookOpen($oExcel_1,$var)
Sleep(300)
_WinWaitActivate("changment data - Excel","")
Send("{ALTDOWN}{SPACE}m{ALTUP}")
MouseClick("left")
MouseDown("left")
MouseMove(150,444)
MouseUp("left")
Send("{ALTDOWN}{SPACE}{ALTUP}{DOWN}{DOWN}{DOWN}{DOWN}{ENTER}")
EndFunc
While 1
Sleep(1)
WEnd
Check out this function it may help you : https://www.autoitscript.com/autoit3/docs/functions/WinExists.htm
you have to add if statement inside the while loop, Example :
While 1
If WinExists($yourwindow) Then
;do whatever you want here..
EndIf
Sleep(1)
WEnd
this function will return true or false value and while the excel is opened it will keep sending true.
I'm got a site with classic asp using vbscript. How can I check if a user is coming from a certain directory on my site? I've got this code
<%Response.Write(Request.ServerVariables("http_referer"))%>
which writes: http://example.com/mobile/REFER.asp. I'd like to write an if/else statement that first checks if the referring uri is in the directory http://example.com/mobile/.
So my code should be something like the below. But I'm not sure about syntax. Is there such a thing as a wildcard character is asp?
<% Request.ServerVariables("http_referer") == "http://example.com/mobile/*"
Eventually I'd like to use that to write an if /else statement
<% if Request.ServerVariables("http_referer") != "http://example.com/mobile/*" then
null; elseif (screen.width <= 699) {
document.location = "/mobile/mobile_home.asp";
} %>
===
Ended up editing #mikeyq6's javascript sample to this which works:
<script type="text/javascript">
if(document.referrer.indexOf('/mobile') > -1 &&
screen.width <= 699) {
document.location = "/mobile/mobile_home.asp";
}
</script>
You know the length of the fixed url you are looking for so just see if the first n characters of the referer match it:
const BASE_DIR = "http://example.com/mobile/"
dim referer: referer = lcase(Request.ServerVariables("http_referer"))
if left(referer, len(BASE_DIR)) = BASE_DIR then
...
else
...
end if
Essentially what you are dealing with is a string, so you can't use wildcards in this way (unless you were to use regular expressions, which is like hitting a nail with a sledgehammer in this case)
It would be much easier to use the InStr function to check to see if the value contains the string you are looking for. Eg:
<% if InStr(Request.ServerVariables("http_referer"), "http://example.com/mobile/") = 0 then
null
elseif (screen.width <= 699) {
document.location = "/mobile/mobile_home.asp";
} %>
More info on InStr here:
http://www.w3schools.com/asp/func_instr.asp
You can do something similar in javascript as well:
if(window.location.href.indexOf("http://example.com/mobile/") > -1 &&
screen.width <= 699) {
document.location = "/mobile/mobile_home.asp";
}
Notice that I simplified the if...else as well. You don't need both cases.
I'm trying to check the username and password in my script
something like that
$username = htmlspecialchars($_POST['username']);
$password = htmlspecialchars($_POST['password']);
$sql = "SELECT * FROM `db_user` WHERE Username='$username' AND Password='$password'";
$query = mysqli_query($db_handle, $sql) or die ("Error in query: " . mysqli_error($db_handle));
$user_row = mysqli_fetch_assoc($query);
mysqli_close($db_handle);
$smarty->assign("DATA", $user_row);
$smarty->assign("USERNAME", $username);
$smarty->assign("PASSWORD", $password);
$smarty->caching=0;
$smarty->display('sign_in.tpl');
in .tpl:
{if $DATA.Username eq $USERNAME and $DATA.Password eq $PASSWORD}
GOOD
{else}
Bad
{/if}
the code is not being applied, and when I send an empty data from the page, I mean not writing any user nor pass, it gives me back "GOOD" message
but when I write anything, no matter if it matches the username and password in the database it still gives me back "BAD" message!!
I've tried to solve this by my own depending on the {debug} function in smarty and here what I've got.
for $DATA: which holds the database information:
Smarty_Variable Object (3)
->value = Array (10)
ID => "14"
Username => "myuser"
Password => "mypass"
Name => "me"
Email => "an email"
Country => "Russia"
Activation => "1"
->nocache = false
->scope = "file:sign_in.tpl"
Smarty is nice, but it kills me when I stop before somethings I used to do with my eyes closed in usual PHP coding -_-
It should work without a problem. However assuming that sometimes no record are found (not valid data) you should add extra check to Smarty template:
{if $DATA neq null and $DATA.Username eq $USERNAME and $DATA.Password eq $PASSWORD}
GOOD
{else}
Bad
{/if}
should do the thing. It's working for me. If it doesn't for you, please provide exact data when it's not working for you ($DATA, $USERNAME and $PASSWORD from Smarty debug).
You should also use prepared statements because now your code is vulnerable to MySQL injection
How do I use vbscript to find two texts that match within a singe line? For example:
This UserName is Logged on already.
How do I search for "UserName" and "Logged on"?
Regular expressions are probably overkill in this case. I'd suggest using InStr() for this kind of check:
s = "This UserName is Logged on already."
If InStr(s, "UserName") > 0 And InStr(s, "Logged on") > 0 Then
'...
End If
You can wrap InStr() in a helper function if you want to make the check a bit better readable:
s = "This UserName is Logged on already."
If Contains(s, "UserName") And Contains(s, "Logged on") Then
'...
End If
Function Contains(str1, str2)
Contains = False
If InStr(str1, str2) > 0 Then Contains = True
End Function