活动目录通知
Active Directory notifications
我看过微软文档中的这个例子,但无法在visual studio 2012中工作,在一个控制台项目下。https://msdn.microsoft.com/en-us/library/ms676877 (v = vs.85) . aspx
我是不是漏掉了什么?控制台应用程序是否正确。
我得到的错误是:
Error 1 error LNK2019: unresolved external symbol __imp__ldap_openW referenced in function "int __cdecl GetChangeNotifications(wchar_t *)" (?GetChangeNotifications@@YAHPA_W@Z) C:projectsAD_NotificationsAD_Change_NotificationsAD_Change_NotificationsAD_Change_Notifications.obj AD_Change_Notifications
从我一直在阅读它的链接错误,这是有点明显,但它都在1个文件,所以我不明白我应该链接什么?
我在java中找到的最好的答案是下面引用的https://community.oracle.com/thread/1158217
/**
* ldapnotify.java
* December 2004
* Sample JNDI application that uses AD LDAP Notification Control.
*
**/
import java.util.Hashtable;
import java.util.Enumeration;
import javax.naming.*;
import javax.naming.ldap.*;
import com.sun.jndi.ldap.ctl.*;
import javax.naming.directory.*;
class NotifyControl implements Control {
public byte[] getEncodedValue() {
return new byte[] {};
}
public String getID() {
return "1.2.840.113556.1.4.528";
}
public boolean isCritical() {
return true;
}
}
class ldapnotify {
public static void main(String[] args) {
Hashtable env = new Hashtable();
String adminName = "CN=Administrator,CN=Users,DC=antipodes,DC=com";
String adminPassword = "XXXXXXXX";
String ldapURL = "ldap://mydc.antipodes.com:389";
String searchBase = "DC=antipodes,DC=com";
//For persistent search can only use objectClass=*
String searchFilter = "(objectClass=*)";
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
//set security credentials, note using simple cleartext authentication
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,adminName);
env.put(Context.SECURITY_CREDENTIALS,adminPassword);
//connect to my domain controller
env.put(Context.PROVIDER_URL,ldapURL);
try {
//bind to the domain controller
LdapContext ctx = new InitialLdapContext(env,null);
// Create the search controls
SearchControls searchCtls = new SearchControls();
//Specify the attributes to return
String returnedAtts[] = null;
searchCtls.setReturningAttributes(returnedAtts);
//Specify the search scope
searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
//Specifiy the search time limit, in this case unlimited
searchCtls.setTimeLimit(0);
//Request the LDAP Persistent Search control
Control[] rqstCtls = new Control[]{new NotifyControl()};
ctx.setRequestControls(rqstCtls);
//Now perform the search
NamingEnumeration answer = ctx.search(searchBase,searchFilter,searchCtls);
SearchResult sr;
Attributes attrs;
//Continue waiting for changes....forever
while(true) {
System.out.println("Waiting for changes..., press Ctrl C to exit");
sr = (SearchResult)answer.next();
System.out.println(">>>" + sr.getName());
//Print out the modified attributes
//instanceType and objectGUID are always returned
attrs = sr.getAttributes();
if (attrs != null) {
try {
for (NamingEnumeration ae = attrs.getAll();ae.hasMore();) {
Attribute attr = (Attribute)ae.next();
System.out.println("Attribute: " + attr.getID());
for (NamingEnumeration e = attr.getAll();e.hasMore();System.out.println(" " + e.next().toString()));
}
}
catch (NullPointerException e) {
System.err.println("Problem listing attributes: " + e);
}
}
}
}
catch (NamingException e) {
System.err.println("LDAP Notifications failure. " + e);
}
}
}
相关文章:
- 函数如何通知用户它基于函数原型抛出异常?
- 如何在ECS框架中更新组件数据和通知系统
- 当 I2C 值在C++中发生变化时收到通知
- 如何设计具有不同类型的通知和观察器的观察者模式?
- 当可输入框在窗口中处于活动状态时获得通知的任何方法
- 是否有必要获取锁并在不需要唤醒线程时通知condition_variable?
- 如何在点击通知时捕获用户的点击操作
- 在通知提升间处理条件变量时未按住锁会导致问题
- 通知条件变量后使用互斥锁
- "错误 (活动) E1696 无法打开源文件 "stdafx.h"--
- 如何在不设置值的情况下通知 c++ 未来?
- glBindTexture 是否覆盖活动纹理单元的内容
- 使用 ISdigit 通知任何检测到的非法字符
- Qt:如何通知对象已建立涉及它的信号槽连接
- 提升进程间named_condition_any不通知
- 当应用程序变为活动/非活动状态时获取通知
- 活动目录通知
- 通知所有活动线程(Windows)
- 如何在没有全局挂钩的情况下获得鼠标/键盘活动的通知
- 当窗口设置为活动状态时获取通知